-
Notifications
You must be signed in to change notification settings - Fork 171
Several enhancements, including CJSX fixes #632
Conversation
e4e882e
to
7e80ca0
Compare
c590760
to
c673321
Compare
Until such time as you start accepting pull requests again, this code (with many more changes) will live at https://github.com/aminland/coffeelint2 named coffeelint2 for coffeescript 2 support. (also works nicely with eslint via my eslint-plugin-coffee) |
Hi. Thanks for the PR There seems to be 3 separate requests in this one PR.
I haven't implemented anything because I haven't spent much time with CSX/CS2. I think if someone started a discussion and had a good way to implement it, I would merge it. But I think handling it for each individual rule sounds like a nightmare. Also it looks like you deleted some tests and some code that don't seem clear to me why you're deleting them. The tests added should also provide enough coverage where I feel confident that the implementation is sound. I'm not saying I need 100 tests, but the tests should appear to have coverage for the general cases. |
Hi, I've added more items since you last looked. In an effort to make this easier I rebased the hell out of my commits so that they're each somewhat self-contained in what they do. In terms of the issues you raised:
What this PR doesn't do is enable new rules to be written that specifically apply only in a CJSX context.
-- |
@@ -24,11 +24,17 @@ task 'compile:commandline', 'Compiles commandline.js', -> | |||
coffeeSync 'src/cache.coffee', 'lib/cache.js' | |||
coffeeSync 'src/ruleLoader.coffee', 'lib/ruleLoader.js' | |||
fs.mkdirSync 'lib/reporters' unless fs.existsSync 'lib/reporters' | |||
fs.mkdirSync 'lib/rules' unless fs.existsSync 'lib/rules' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed so we can export the default rules for use in eslint.
@@ -18,6 +18,9 @@ | |||
"space_operators": { | |||
"level": "error" | |||
}, | |||
"max_line_length": { | |||
"value": "100" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80 is just wayyy too low, it was causing issues in the test files. Easier to just up the limit than to adhere to a dogmatic 80.
@@ -32,8 +32,8 @@ | |||
"strip-json-comments": "^1.0.2" | |||
}, | |||
"devDependencies": { | |||
"vows": ">=0.8.1", | |||
"underscore": ">=1.4.4" | |||
"underscore": ">=1.4.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm automatically alphabeticalizes now.
@@ -310,9 +309,10 @@ coffeelint.lint = (source, userConfig = {}, literate = false) -> | |||
|
|||
# only do further checks if the syntax is okay, otherwise they just fail | |||
# with syntax error exceptions | |||
unless hasSyntaxError(source) | |||
tokens = getTokens(source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we were passing the source to Coffeescript before twice, which basically means we're doing twice as much work as needed.
return null if not config[attr]? | ||
config = config[attr] | ||
|
||
config.__location__ = filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so we can remember where the config file is loaded from, so we can resolve the "extends" property relative to the location of the configfile (as opposed to the cwd)
unless config.extends | ||
return config | ||
try | ||
parentConfig = require resolve config.extends, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we cant resolve the path relative to our present directory, then we can look in node_modules
@@ -18,10 +18,10 @@ BaseLinter = require './base_linter.coffee' | |||
# | |||
module.exports = class LexicalLinter extends BaseLinter | |||
|
|||
constructor: (source, config, rules, CoffeeScript) -> | |||
constructor: (source, config, rules, CoffeeScript, tokens) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so we can pass in the tokens from coffeelint.coffee (so we're not running CoffeeScript.tokens(source)
twice)
@@ -57,7 +60,8 @@ module.exports = class ColonAssignmentSpacing | |||
[isLeftSpaced, leftSpacing] = checkSpacing 'left' | |||
[isRightSpaced, rightSpacing] = checkSpacing 'right' | |||
|
|||
if isLeftSpaced and isRightSpaced | |||
if token.csxColon or isLeftSpaced and isRightSpaced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have no control over spacing of "csxColons" (these are autogenerated by the compiler)
@trackStringStart() | ||
@blocks = [] | ||
|
||
lintToken: (token, tokenApi) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote this function from scratch. To test for nested interpolation the old way is problematic since {} code blocks inside CSX tags are treated as nested interpolation in the old scheme.
In the new way, we keep track of visited string_start and string_end per csx tag. Each time we encounter a csx tag, we nest to another 'block', with its own tracking.
@@ -5,6 +5,7 @@ module.exports = class PreferEnglishOperator | |||
level: 'ignore' | |||
message: 'Don\'t use &&, ||, ==, !=, or !' | |||
doubleNotLevel: 'ignore' | |||
ops: ['and', 'or', 'not', 'is', 'isnt'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just a preference thing. Rather than making a new custom rule that does a subset of what this rule does, the rule is now configurable so people can specify which english operators they prefer. Much nicer this way, for those who aren't a fan of "isnt" as an operator...
# Coffeescript does some code generation when using CSX syntax, and it adds | ||
# brackets & commas that are not marked as generated. The only way to check | ||
# these is to see if the comma has the same column number as the last token. | ||
isGenerated: (token, tokenApi) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can be simplified later if the underlying coffeescript lexer starts marking things as generated.
…, not just in node_modules
If you really want me to split to multiple PRs I can, but i don't see a need as I don't think i've done anything controversial... |
What's the status here, can this be merged - or should separate PRs be submitted - or something else? I need jsx support on my project so would be nice to have this on the main repo instead of having to use a different package. |
bump. |
This will be added to @coffeelint/cli in coffeelint/coffeelint#8. Thanks! |
Fixes colon and comma spacing issues from CSX (JSX) format described in #629