Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: move eslint to new plugin system #18566

Closed
wants to merge 1 commit into from

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Feb 4, 2018

this allows any global eslint install to run the eslint, letting editor's eslint addons lint node source as you edit it. i realize this is quite hacky but it seems fairly worth it for the ease of editing. this also moves all our custom eslint rules to a node namespace as a side-effect which seems to me like a bonus.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

lint

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Feb 4, 2018
@vsemozhetbyt vsemozhetbyt added the tools Issues and PRs related to the tools directory. label Feb 4, 2018
@vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt
Copy link
Contributor

Should the vcbuild.dat be also updated for local linting on Windows?

.eslintrc.js Outdated
if (!r && hacks.includes(request))
return require.resolve(`./tools/node_modules/${request}`);
return r;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to monkeypatching the module resolution code, you could also use something like eslint-plugin-rulesdir.

Copy link
Member Author

@devsnek devsnek Feb 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually started by looking at things like that. eslint-plugin-rulesdir solves a different problem. the eslint-plugin-node plugin actually does mostly the same thing as eslint-plugin-rulesdir. the reason i monkeypatch is because eslint doesn't know (rightfully so) to look in tools/node_modules for babel-eslint and eslint-plugin-node. eslint accepting relative paths to plugins/parsers would allow me to get rid of the module patch, but the issues/prs surrounding that for eslint seem to have stalled so i just did this instead.

@vsemozhetbyt
Copy link
Contributor

Sorry for the conflict after #18569, this needs rebasing)

@devsnek devsnek force-pushed the refactor/eslint branch 3 times, most recently from 0e1d2b3 to 78d105c Compare February 5, 2018 03:20
@devsnek
Copy link
Member Author

devsnek commented Feb 5, 2018

@vsemozhetbyt this should be gtg, and probably fast-track-able?

@vsemozhetbyt
Copy link
Contributor

сс @not-an-aardvark, @silverwind, @Trott

@silverwind
Copy link
Contributor

Yay, editor integration working again. I noticed these errors when running on the CLI, can anyone reproduce?

$ eslint lib/assert.js

/Users/silverwind/git/node/lib/assert.js
  1:1  error  Definition for rule 'node/no-unescaped-regexp-dot' was not found       node/no-unescaped-regexp-dot
  1:1  error  Definition for rule 'node/buffer-constructor' was not found            node/buffer-constructor
  1:1  error  Definition for rule 'node/no-let-in-for-declaration' was not found     node/no-let-in-for-declaration
  1:1  error  Definition for rule 'node/lowercase-name-for-primitive' was not found  node/lowercase-name-for-primitive
  1:1  error  Definition for rule 'node/non-ascii-character' was not found           node/non-ascii-character
  1:1  error  Definition for rule 'node/require-buffer' was not found                node/require-buffer

@devsnek
Copy link
Member Author

devsnek commented Feb 6, 2018

@silverwind i can't reproduce it, perhaps you can do a little digging?

@silverwind
Copy link
Contributor

Hmm, not sure where to start looking. BTW, is it intentional that eslint-plugin-markdown has to be installed globally? Maybe we should document these global dependencies somewhere.

.eslintrc.js Outdated
@@ -0,0 +1,222 @@
const NodePlugin = require('./tools/node_modules/eslint-plugin-node');
NodePlugin.RULES_DIR = 'tools/eslint-rules';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this path be path.join(__dirname, 'tools', 'eslint-rules'), so that eslint can be called from subdirectories too?

Copy link
Member Author

@devsnek devsnek Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silverwind i wasn't able to figure out what markdown was doing, it wasn't in tools/node_modules and i don't have it installed globally so i assumed it was builtin to eslint and didn't think about it any further, but i will make that change for the rules dir, good catch 😄

Copy link
Contributor

@silverwind silverwind Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's in tools/node_modules/eslint/node_modules. I got the error about it missing when running my global eslint without the plugin installed globally but if you don't see these errors, I think something might be wrong in my setup. I use yarn for global modules, if that matters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, i have modified the script to fix this thanks 😄

@devsnek devsnek force-pushed the refactor/eslint branch 3 times, most recently from ebdce6f to 4d2995b Compare February 6, 2018 21:02
.eslintrc.js Outdated
NodePlugin.RULES_DIR = path.resolve(__dirname, 'tools', 'eslint-rules');

const ModuleFindPath = Module._findPath;
const hacks = ['eslint-plugin-node', 'eslint-plugin-markdown', 'babel-eslint'];
Copy link
Member

@joyeecheung joyeecheung Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use eslint-plugin-node-core as the namespace since eslint-plugin-node is already taken and seems quite popular? I have put a placeholder in eslint-plugin-node-core to export these rules out (currently empty, the prototypes are in @joyeecheung scope until we figure out how how it's going to be adopted)

Copy link
Member Author

@devsnek devsnek Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that sounds ok, once they move to nodejs's namespace on github i can integrate them into this pr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I am not an expert on eslint but I think if we publish eslint-plugin-node-core to npm and install them globally, the editors are going to work as well? (The error documentation rules would be a bit tricky since they need to read doc/api/errors.md though)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if installed globally and run with global eslint install then yes it would work 👍

@BridgeAR
Copy link
Member

Ping @devsnek

@devsnek
Copy link
Member Author

devsnek commented Feb 16, 2018

@BridgeAR this is kinda sitting while i wait to see what happens with nodejs/admin#55

@joyeecheung
Copy link
Member

@devsnek Since this is already in working shape, maybe we can just use the node-core namespace now (since it's taken we don't need to worry about potential conflicts) and land this. When they do get published npm the users can then use them without the hack

@devsnek
Copy link
Member Author

devsnek commented Feb 17, 2018

@devsnek
Copy link
Member Author

devsnek commented Feb 17, 2018

@joyeecheung pr uses node-core namespace now

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one suggestion

return r;
};

module.exports = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to put these into a separate file (either a JSON or a .js), and re-export that from here. That way we can separate the hack from the actual rules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd rather not just for simplicity's sake

@devsnek
Copy link
Member Author

devsnek commented Feb 20, 2018

landed in 6934792

@devsnek devsnek closed this Feb 20, 2018
devsnek added a commit that referenced this pull request Feb 20, 2018
PR-URL: #18566
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
@devsnek devsnek deleted the refactor/eslint branch February 20, 2018 19:14
@MylesBorins
Copy link
Contributor

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Feb 22, 2018
This adds the eslint rules back in that were falsely removed while
landing nodejs#18566.

Refs: nodejs#18566
@BridgeAR
Copy link
Member

Seems like this removed a couple of rules that landed since the PR was originally opened.

I opened a PR to fix those: #18933

So if this is backported, please include that fix as well.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Feb 22, 2018
This adds the eslint rules back in that were falsely removed while
landing nodejs#18566.

PR-URL: nodejs#18933
Refs: nodejs#18566
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Mar 5, 2018
4 tasks
@devsnek devsnek removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 18, 2018
@MylesBorins
Copy link
Contributor

Hey all... this is blocking updating the eslint rules for all previous release lines. Can we please get this backported to v9.x -> v6.x

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Mar 20, 2018

If anybody looks into this deeply, please consider finding a fix for the #19250 (concise investigation in #19250 (comment))

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
PR-URL: nodejs#18566
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
BridgeAR added a commit to BridgeAR/node that referenced this pull request May 1, 2018
This adds the eslint rules back in that were falsely removed while
landing nodejs#18566.

PR-URL: nodejs#18933
Refs: nodejs#18566
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
PR-URL: nodejs#18566
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
This adds the eslint rules back in that were falsely removed while
landing nodejs#18566.

PR-URL: nodejs#18933
Refs: nodejs#18566
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
boneskull added a commit to boneskull/node that referenced this pull request Jun 21, 2018
@boneskull boneskull mentioned this pull request Jun 21, 2018
1 task
Trott pushed a commit to Trott/io.js that referenced this pull request Jun 21, 2018
Refs: nodejs#18566

PR-URL: nodejs#21449
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos pushed a commit that referenced this pull request Jun 22, 2018
Refs: #18566

PR-URL: #21449
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@MylesBorins
Copy link
Contributor

Ping re 8.x backport

needs to come with #18933

@MylesBorins
Copy link
Contributor

another ping for 8.x update for the eslint stuff /cc @Trott

@Trott
Copy link
Member

Trott commented Aug 19, 2018

@MylesBorins I believe this will be easier to backport if #17820 lands on 8.x-staging first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants