clutchski / coffeelint Goto Github PK
View Code? Open in Web Editor NEWLint your CoffeeScript.
Home Page: http://www.coffeelint.org
License: Other
Lint your CoffeeScript.
Home Page: http://www.coffeelint.org
License: Other
The code is valid:
@collection
.fetch()
.done =>
$button.removeAttr('disabled')
@trigger 'sync'
or
[1, 2, 3]
.map (a) ->
a * 2
.filter (a) ->
a > 3
linter says:
17 Sep 03:46:56 - error: Linting of 'app/views/user/user_repo_sync_view.coffee' failed. error: indentation at line 27.Expected 2 got -2
All operators should have whitespace around them.
a | b # good
a|b # bad
The following file with a Windows newline (CR+LF) after the semicolon passes trailing semicolon detection:
x = 5;
V test.coffee
V Ok! » 0 errors and 0 warnings in 1 file
If I change to a Unix newline, I get:
? #1: Line contains a trailing semicolon.
? Lint! » 1 error and 0 warnings in 1 file
when -f is not specified, look for coffeelint.json under current directory
I think it would be great to ignore trailing whitespaces in comments.
Use-Case:
Coffeedoc uses Markdown, in markdown trailing whitespaces mean newline.
Maybe there's another way to force newlines with markdown? I'm quite new to it and would like the idea of not having trailing whitespaces.
If there's not - I think coffeelint should have a switch to turn the trailing-whitespaces check off for comments. Would that be OK?
Coffeelint should be CI-friendly.
It should return shell exit codes. In this case coffeelint can be integrated together with CI-servers.
I noticed that defining methods on a class seems to make cofeelint complain about "Implicit braces are forbidden" when the "implicit_braces" option is set to "error". Defining methods seems to actually have the same syntax as creating an object without braces, but it's different semantics when it comes right after a class declaration.
test.coffee
class Test
method: ->
"hello"
test.json
{
"no_implicit_braces" : {
"level" : "error"
}
}
Output
✗ test.coffee
✗ #2: Implicit braces are forbidden.
✗ Lint! » 1 error and 0 warnings in 1 file
https://github.com/polarmobile/coffeescript-style-guide should be followed with optional rules:
and
, or
, is
, isnt
not
&&
, ||
, ==
, !=
, !
unless-else
. Should be rewritten as if-else
to be much clearer@
, this.prop
instead of @prop
(gh-18)() ->
)a, b, c
)when error encontered exits with 1, so that coffeelint can be used in scripts
There should be no need to press a button to perform the linting. Every keypress/change should trigger a re-linting. Also, there's currently no visual cue that the linting was performed when the lint status remains the same.
I'd like to be able to pipe coffeescript directly into coffeelint. Just like with coffeescript's --stdio.
This would make it easier to check code that is not saved to a file or only fragments of an existing file.
As an example: with TextMate I have to write the selection to a temporary file, pass it to coffeelint, and delete it.
TextMate command:
#!/bin/bash
cat ${TM_COFFEE} > /tmp/coffeelint
coffeelint /tmp/coffeelint
rm /tmp/coffeelint
I'm invoking CoffeeLint in a script called from a Visual Studio build event. The problem is that the ANSI-colored output doesn't show in the Visual Studio output window.
It would be nice to have an option to skip ANSI coloring.
I would like to propose that a --bail
argument to can be passed to coffeelint, and which when passed would ensure that an error would be thrown after the first parsed file containing any erroneous lints.
This way, coffeelint could be used to force consistency automatically when being invoked from a makefile and/or through continuous integration.
Here's how I would imagine it to work:
find src/js -name "*.coffee" -type f -exec coffeelint -f coffeelint.json --bail {} \;
✗ src/js/one.coffee
✗ #1: Line ends with trailing whitespace.
✗ Lint! » 1 error in 1 file
// Throw error here and exit if --bail argument was passed.
Print only file names with some errors or warnings or nothing. Just like pep8.
There should be some way to ignore sub directories (specifically, node_modules) when using the -r flag, otherwise installed modules could cause the linter to print errors that aren't the concern of the user.
Is this planned?
I'm trying to lint my coffee and get the output into something Jenkins can use thru the Violations plugin. I could always use JSHint with the proper configuration file used by Ashkenas but it would be nice for CoffeeLint to support this out of the box.
We document our code in comments using coffeedoc, and would prefer not to have to worry about hand-wrapping this documentation, since the browser will be the one to display these in their final form.
It would be nice to have an option to ignore line length of comment-only lines while still caring that code is not complex enough to reach X number of characters in length.
Hello, I am pretty new to bash and Terminal, so any help would be appreciated.
After installing CoffeeLint locally, I try to run it with:
$ coffeelint application.coffee
And I am met with:
-bash: coffeelint: command not found
I am assuming this in issue with my $PATH variable. When I enter:
$ echo $PATH
This is the $PATH given:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
Any recommendations on how to correct this issue?
Thank you.
Anybody interested in getting this going with: https://github.com/Kronuz/SublimeLinter ?
The current version of their coffeescript linter only really just checks for compile errors.
I want it, and will probably build it unless somebody is much keener and beats me to it
would it be possible to do this?
would be particularly useful to get the command line stuff going:
SublimeLinter/SublimeLinter#118 will rely on this
not meaning to be pushy - if there's a particular reason not to release then don't do so prematurely
I'm having a strange problem on Windows when shelling out to CoffeeLint on Windows. Using the following code:
terminal = require("child_process").spawn("node", ["node_modules/coffeelint/bin/coffeelint", "-v"])
terminal.stdout.on "data", (data) ->
console.log "stdout: " + data
terminal.stderr.on "data", (data) ->
console.log "stderr: " + data
terminal.on "exit", (code) ->
console.log "child process exited with code " + code
the output on windows is:
Z:\Code>coffee test.coffee
child process exited with code 0
Commenting out the process.exit()
calls (https://github.com/clutchski/coffeelint/blob/master/src/commandline.coffee#L224) fixes it. It seems like the process is exiting before it has a chance to print because if I wrap the process.exit()
with setTimeout(..., 100)
it works fine.
All function arrows should have either whitespace or newline characters following them.
-> a # good
->a # bad
this valid coffeescript triggers the wrong error when calling a function in class body:
class A
@configure(1, 2, 3)
constructor: ->
pattern used all over the place by the spine framework
edit: that is, with the "no_implicit_braces" set to "error" of course, and which have nothing to do with the preceding example
I think the no_implicit_braces rule is good -- when we're dealing with one liners where there may be some confusion. I don't think that multi-line / indented object definitions are problematic. This is really similar to issue #21 - #21
I'm OK with this personally:
foo =
bar:
baz: 1
thing: 'a'
baz: ['a', 'b', 'c']
But not OK with something like
foo = bar: { baz: 1, thing: 'a' }, baz: ['a', 'b', 'c']
I think it would be nice to allow a value to be specified in the options to change the behavior to only generate errors for inline vs mult-line definitions.
Thoughts?
I was just rewriting the example on the website a little, when this code
# Lint your CoffeeScript!
Gangster = (class then wasItAGoodDay : -> yes)
turned up this error:
Your code has lint.
Line #3:Class names should be camel cased
Would love to be able to pass a directory and have all of its contents recursively lint-checked
One thing we tend to do is bring a method call which takes a function as a parameter to a new line. When we indent the body the function parameter things get weird.
somObject.method ()->
object:
withValue: 'val'
andValue: 'val'
// Generated by CoffeeScript 1.3.3
somObject.method(function() {
return {
object: {
withValue: 'val',
andValue: 'val'
}
};
});
somObject
.method ()->
object:
withValue: 'val'
andValue: 'val'
// Generated by CoffeeScript 1.3.3
somObject.method(function() {
return {
object: {
withValue: 'val',
andValue: 'val'
}
};
});
The "NOT OK" example complains about indentation at .method ()->
We would like to use this indentation style since its useful for chaining and some internal DSLs.
Wouldn't be useful if coffeelint checked for errors before checking for style inconsistencies?
Bound functions without any references to their context anywhere in their immediate scope (or their bound children's scope, recursively tested) should produce a warning.
=> this # good
=> "this" # bad
=> => => => this # good
=> -> => => this # bad
Hello, trying to set the style for my mysql calls and coffeelinting the code I get an "inconsistent indentation" warning on the callback function body. Indenting in the same level as the arguments and function declaration removes the warning but I think it should not raise any warnings at it.
Is it the intended behavior?
mysql.query \
"""
SELECT
`user_id` as `id`,
`user_name` as `name`,
`user_password` as `password`
FROM
`users`
WHERE
`user_name` = ?
LIMIT 1
""",
['test'],
(err,res) ->
console.log err
console.log res[0]
Also, thank you for the good work! :)
Correctly indented code shows error:
$div.find("#tableList").hammer(buttonHammerOptions)
.on 'tap', (event) ->
if UI.tapReady
✗ #3: Line contains inconsistent indentation. Expected 2 got -2.
Most Lint checkers (for other languages) have this feature, I find it to be very useful to catch typos (read http://stackoverflow.com/questions/9835697/is-there-a-way-to-catch-typos-when-writing-coffeescript for an example).
CamelCase is a generic name that can mean camelCase or CamelCase. When you want to specify initial caps explicitly, it's called PascalCase.
Any chance of a coffeelint textmate bundle in the near future?
It would be fantastic to be able to lint on save, and have a more detailed HTML window the same as the jslint bundle for textmate.
Standalone @
will be disallowed eventually. See jashkenas/coffeescript#1601. It's currently discouraged. You could call it deprecated.
The issue shows up with a file structure like this:
./application.coffee
./application.sass
./random.js
./src/some_module.coffee
./styles/some_stylesheet.sass
Coffeelint will correctly not parse ./styles/some_stylesheet.sass
, but it will attempt to parse ./application.sass
and ./random.js
. Right now I'm just using ack and xargs to make it work.
ack -g coffee$ | tr '\n' ' ' | xargs coffeelint
Thanks for an awesome tool. :)
I'm using grunt-coffeelint to run coffeelint over coffeescript code, and that works fine.
Now I need to make grunt generate output that can be sucked up by Jenkins. I see the --jslint command line option which is great.
However, the grunt task doesn't go through the CLI -- it just directly loads the linter, and passes it JSON for options.
https://github.com/vojtajina/grunt-coffeelint/blob/master/tasks/coffeelint.js#L11
Without digging into the CLI parsing code... is there an easy way to pass --jslint without using the command line?
Minimatch, as far as I can see, is only available with a version number of 0.1.5. I'm confused as to why coffeelint is looking for > version 2.
matthewbeale:~ node -v
v0.8.7
matthewbeale:~ npm -v
1.1.51
matthewbeale:~ sudo npm install -f -g coffeelint
npm http GET https://registry.npmjs.org/coffeelint/-/coffeelint-0.4.0.tgz
npm http 200 https://registry.npmjs.org/coffeelint/-/coffeelint-0.4.0.tgz
npm http GET https://registry.npmjs.org/optimist/-/optimist-0.3.4.tgz
npm http GET https://registry.npmjs.org/coffee-script/-/coffee-script-1.2.0.tgz
npm http GET https://registry.npmjs.org/glob/-/glob-3.1.12.tgz
npm http 200 https://registry.npmjs.org/glob/-/glob-3.1.12.tgz
npm http 200 https://registry.npmjs.org/coffee-script/-/coffee-script-1.2.0.tgz
npm http 200 https://registry.npmjs.org/optimist/-/optimist-0.3.4.tgz
npm http GET https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.1.5.tgz
npm http GET https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz
npm ERR! Error: No compatible version found: minimatch@'>=0.2.0- <0.3.0-'
npm ERR! Valid install targets:
npm ERR! ["0.0.1","0.0.2","0.0.4","0.0.5","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5"]
npm ERR! at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:553:10)
npm ERR! at next (/usr/local/lib/node_modules/npm/lib/cache.js:532:17)
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:512:5
npm ERR! at RegClient.get_ (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:101:14)
npm ERR! at RegClient.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:37:12)
npm ERR! at fs.readFile (fs.js:176:14)
npm ERR! at fs.close (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:92:5)
npm ERR! at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-f" "-g" "coffeelint"
npm ERR! cwd /Users/matthewbeale
npm ERR! node -v v0.8.7
npm ERR! npm -v 1.1.51
npm ERR! Error: ENOENT, lstat '/usr/local/lib/node_modules/coffeelint/node_modules/coffee-script/lib/coffee-script/nodes.js'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-f" "-g" "coffeelint"
npm ERR! cwd /Users/matthewbeale
npm ERR! node -v v0.8.7
npm ERR! npm -v 1.1.51
npm ERR! path /usr/local/lib/node_modules/coffeelint/node_modules/coffee-script/lib/coffee-script/nodes.js
npm ERR! fstream_path /usr/local/lib/node_modules/coffeelint/node_modules/coffee-script/lib/coffee-script/nodes.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack Writer._finish.er.fstream_finish_call (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/writer.js:284:26)
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm http 200 https://registry.npmjs.org/inherits/-/inherits-1.0.0.tgz
npm http 200 https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.1.5.tgz
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/matthewbeale/npm-debug.log
npm ERR! not ok code 0
Ignore the sudo, I know it's bad but it should be unrelated. I forced to try and overcome the minimatch dependency.
CoffeeLint is in it's infancy
To enable an option, set it's level to
error
and to disable an option, set it's level toignore
.
The word "it's" means "it is" exclusively. The word in these two instances should be "its" (possessive).
(The remaining usage of the word "it's", in "it's critical", is correct.)
Yes, I care enough to even file bug reports for things like this.
having whitespace on an empty line does not trigger the trailing-whitespace rule, even though leading whitespace might exist due to autoindenters... might be nice to have a separate rule for this corner case?
# blahblah
# next line contains trailing whitespace (really, though markdown strips it!)
EOF
was expecting it to trigger "Line 3 contains trailing whitespace"
I have a coffee file with a UTF-8 BOM marker that begins with a @:
<U+FEFF>@foo = bar
Coffeelint gives:
test.coffee(1): error: Error: Parse error on line 1: Unexpected '@'
If I start the file with an empty line, the error goes away.
There are two options for fixing this, we can raise the maximum cyclomatic complexity, or rewrite some of the more complex stuff (the new block disabling stuff mostly).
Since there seems to no easy way to rewrite it with less complexity I am opening up this issue for discussion.
I'm trying to run coffeelint on all files in a directory and eventually want to use -r to run it on my entire source tree.
I've tried the following (my coffeescript directory is 'coffee' inside the current directory):
coffeelint coffee
coffeelint coffee/
coffeelint coffee/*.coffee
The first two result in this exception:
var r = binding.read(fd, buffer, offset, length, position);
^
Error: UNKNOWN, unknown error
at Object.readSync (fs.js:283:19)
at Object.readFileSync (fs.js:142:21)
at C:\Users\chris\AppData\Roaming\npm\node_modules\coffeelint\bin\coffeelint
:33:15
at C:\Users\chris\AppData\Roaming\npm\node_modules\coffeelint\bin\coffeelint
:289:16
at Object.<anonymous> (C:\Users\chris\AppData\Roaming\npm\node_modules\coffe
elint\bin\coffeelint:346:21)
at Object.<anonymous> (C:\Users\chris\AppData\Roaming\npm\node_modules\coffe
elint\bin\coffeelint:351:4)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
The one with the * gives me this one:
return binding.stat(pathModule._makeLong(path));
^
Error: ENOENT, no such file or directory '<my-directory>\coffee\*.coffee'
at Object.statSync (fs.js:424:18)
at Object.realpathSync (fs.js:805:8)
at C:\Users\chris\AppData\Roaming\npm\node_modules\coffeelint\bin\coffeelint
:32:19
at C:\Users\chris\AppData\Roaming\npm\node_modules\coffeelint\bin\coffeelint
:289:16
at Object.<anonymous> (C:\Users\chris\AppData\Roaming\npm\node_modules\coffe
elint\bin\coffeelint:346:21)
at Object.<anonymous> (C:\Users\chris\AppData\Roaming\npm\node_modules\coffe
elint\bin\coffeelint:351:4)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
This is on Windows 7 with the latest version from the Git master branch. Running coffeelint on an individual file works fine.
What am I doing wrong?
myfun = ->
foo = bar
It should warn about the undefined bar variable. This something I miss the most from jshint/jslint.
I'm not sure this is a bug, it smells weird to me, thought I'd report
obj
.method
param: "val" # Line contains inconsistent indentation
obj.
method
param: "val" # Line contains inconsistent indentation
obj
.method(
param: "val" # Line contains inconsistent indentation
)
obj
.method
param: "val" # Line contains inconsistent indentation
obj.
method
param: "val" # Line contains inconsistent indentation
obj
.method(
param: "val" # Line contains inconsistent indentation
)
obj
.method()
obj.
method()
obj
.method()
obj.
method()
a = () ->
obj # Line contains inconsistent indentation
.method
param: "val"
obj
.method
param: "val"
a = () ->
obj. # Line contains inconsistent indentation
method
param: "val"
obj.
method
param: "val"
a = () ->
obj # Line contains inconsistent indentation
.method(
param: "val"
)
obj
.method(
param: "val"
)
a = () ->
obj # Line contains inconsistent indentation
.method(
param: "val"
)
obj
.method(
param: "val"
)
To me the visual cue to signify a function call is the parenthesis. I can't stand when they are left off. It would be really nice if there were an option for this.
One space should be used on each side of the equals character.
I know it's a bit nitpicky, but then again, this is a lint :-)
Basic description of what I mean:
I was very confused when I thought I was using camelCase and I was getting errors about it...
Thanks,
Frankie
Maybe finishing touches of #44
Needs at least
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.