Giter Club home page Giter Club logo

navel's Introduction

navel

You can contribute to this project by voicing your opinion about what rules a cfscript linter should have. (For the sake of sanity, this project is for cfscript only.)

See the issues list and wiki.

I'm currently working on getting a basic cfscript parser working in JISON before implementing the lint rules. Feel free to contribute to that as well: cflint.jison

navel's People

Contributors

russplaysguitar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

navel's Issues

"global" directive

Since the linter fails for non-scoped, non-local variables (see: #17 ), there should be a "global" directive (similar to jshint) which allows you to specify which variables exist in the global namespace. This would be a linter option and an option in comments at the top of a file // global: varNameHere

I don't think that this should apply to CFCs (since having to declare all the CFCs within the "global" directive would get annoying pretty fast). So basically, if new is being used, the linter won't fail. Example pass: var x = new X().

(note: both "global" and "globals" keywords should work to reduce pointless frustration)

return rule

The linter should require a return statement (with a variable or constant) for functions with return types other than void. If a void return-type function has a return statement (with a variable or constant), it should not pass lint.

Sample passes:

function numeric numFunc() {
   return 1;
}

function numeric numFunc() {
   var x = 1;
   return x;
}

function void voidFunc() {

}

function void voidFunc2() {
   return;
}

Sample fails:

function numeric numFunc() {

}

function numeric numFunc2() {
   return;
}

function void voidFunc() {
   return 1;
}

function void voidFunc2() {
   var x = 1;
   return x;
}

bracket [] notation

Instead of alternating between do-notation and bracket-notation to access static struct keys and variable struct keys, respectively, always use bracket-notation:

YES: myStruct['item1'][var1]
NO: myStruct.item1[var1]

Aside from being more consistent, bracket-notation respects the case of your keys, and does not UPPERCASE them. This is very important when, for example, you are serializing your structs to send to backend services, and similar. The only disadvantage is the additional character you have to type (2 brackets instead of 1 period).

Closing of CFML tags

It's a fairly opinionated topic, but having a rule to enforce either the presence or absence of meaningless-but-popular self-closed CFML tags would be a good 'un.

EG:

<cfset foo = "bar" />
<cfset bar = "foo">

Would raise a warning because of the mix of styles.

This should be something that should be settable to either require (as much as it's enforceable in CFML) self-close tags, or prohibit them.

ArrayNew(1)

Since ArrayNew(1) is equivalent to [], use of ArrayNew(1) should fail lint.

basic struct functions

Seems like some of the struct functions are outdated. Here is a list that I think should cause warnings:

  • structFind
  • structGet
  • structInsert
  • structNew
  • structUpdate

Decision operators

The use of "decision operators" should cause lint failures. Examples IS, IS NOT, EQ, NEQ, etc...

Boolean operations should be used instead.

Array index of 0

Attempts to access array index of zero (or negative values) should fail lint.

Example failures:

var x = myArray[0];

myArray[0] = 1;

var x = myArray[-1];

I can't think of any time when you'd even write [0] (or have a negative constant index) in cfml.

JavaDoc style comments

I believe strongly that comments should not affect code execution. If I were going to use a CFScript linter, I would definitely disallow them.

I agree that they look better than function metadata as weird name/value pairs after the argument list... but I'd rather explain ugly syntax to a new programmer than that only a certain type of comments affect the way code executes.

isDefined()

The use of isDefined() should probably cause a lint warning that suggests the use of structKeyExists() instead.

Custom lint rules?

It might be useful if custom lint rules could be defined on a per-component basis. It could be used for situations where it is bad practice to use a component a certain way, but that doing so won't throw an error.

For instance, if you're supposed to call obj.close() after obj.open(), the linter could check for that.

This gets into some pretty insane meta-programming and I have no idea how this would be implemented, but I thought I'd bring it up anyways. Definitely falls into the "nice to have", low-priorty category.

use of # signs

Unnecessary use of pound signs should fail lint. Wrapping them in quotations should warn unless there are other characters included.

Example fail:

x = #y#;

Example warn:

x = "#y#";

Example pass:

x = "y is #y#";

struct definitions: colons vs. equals signs

Since both equals and colon notation can be used in the newest versions of CF, should the linter prefer one or the other?

Examples:

var myStruct = {
   myValue: "value"
};

or

var myStruct = {
   myValue = "value"
};

Both of these are valid in CF 10 and Railo 4.

Support for multiple versions?

Obviously it would be easiest to only support the latest Railo/Coldfusion versions (currently 4 and 10, respectively), but there might be cases where it could be useful to support multiple versions?

I could see it being helpful if the linter identified unsupported features for your version, but then again, the JIT compiler would throw an error in that case too.

use of & sign with numbers

Use of ampersand with numbers should fail. Constant numbers used with the ampersand sign must be wrapped with quotation marks.

Example fail:

x = 1 & 2;

Example pass:

x = "1" & "2";

Experimenting with Mocha for unit tests

I've started playing with Mocha for unit tests. What I've got so far is shared as the mocha-experimental branch.

If you're familiar with Node at all the Readme (with my modifications) should get you up to speed on running the tests. The test code itself is easily read.

I'll comment on this thread requesting feedback/etc as appropriate. Feel free to ask questions/etc here so that others who need help getting up to speed can learn from the public discussion.

cflock

lint should fail if shared scope variables (application, server, session, or request) are set without being wrapped in a lock block with the appropriate scope. (it would be great if the lock type exclusive could be linted too).

lint should also fail if shared scope variables are accessed without being wrapped in duplicate().

General lint rule discussion

You can either create a new issue for a specific lint rule or bring up some random stuff for discussion here. Keep in mind that this is meant to be a cfscript linter, not for cf tags.

Variable scoping

This is kind-of a big one. Should the linter fail/warn when using unscoped variables? Is it okay to use variables without a scoping prefix if they have been declared with var?

Personally, I think the linter should fail if an unscoped variable is used which hasn't been declared with var.

Which license should we use?

I'm partial to the MIT License, which to the best of my understanding is functionally equivalent to the WTFPL, with more business-friendly language. I have also used the Apache license in the past.

BSD is also popular for being more lenient than GPL. Personally, I avoid GPL.

parameterExists()

use of parameterExists() should fail lint. structKeyExists() should be used instead.

ALL CAPS

using all caps for any code (variables or reserved words) should fail lint.

cfml doesn't support constants-as-variables, so the use of all caps to imply constancy is misleading at best.

Consider rename?

So if you're not familiar, the oddly named CFEngine tool has also inspired its own linter, also named CFLint.

I would venture to guess (but it is a guess) that many more enterprise businesses are using CFEngine than businesses (of any type) are using ACF. Perhaps it would be wise to come up with another name to avoid confusion?

</$0.02>

What language should the linter be written in?

Yes, we could do it in CF, but I don't think that would work out very well considering how I personally want to use the linter (as a Sublime Text plugin). Also, I don't know of any parsers written in CF.

My top picks are: JS, Ruby, or Python.

For JS, we could use jison

IIF() and DE()

IIF() should cause a failure and suggest the use of the ternary operator instead.
DE() should cause a failure.

ORM rules?

I haven't used ORM much, so I'm not familiar with corresponding best practices. Please share your thoughts.

Rules for things which throw errors already

I don't think we should write lint rules that duplicate errors which are already thrown by the engine (for example #9 ). Seems like it would generate a fair amount of additional work that might not be necessary.

incrementValue() and decrementValue()

Use of incrementValue() should cause a lint warning and suggest ++ instead. (Or should it suggest +=1?)

(Also decrementValue() should be handled similarly)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.