Skip to content

Commit

Permalink
Load custom eslint rules as plugin, w/o --rulesdir
Browse files Browse the repository at this point in the history
This allows us to load the eslint rules without requiring command-line
arguments, which avoids breaking editors with eslint plugins.

eslint/eslint#2180 (comment)
  • Loading branch information
bgw committed Jun 5, 2015
1 parent 58302a7 commit 30cce21
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parser: babel-eslint

plugins:
- react
- react-internal

env:
browser: true
Expand Down Expand Up @@ -97,4 +98,4 @@ rules:

# CUSTOM RULES
# the second argument of warning/invariant should be a literal string
warning-and-invariant-args: 2
react-internal/warning-and-invariant-args: 2
5 changes: 5 additions & 0 deletions eslint-rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Custom ESLint Rules

This is a dummy npm package that allows us to treat it as an eslint-plugin. It's not actually published, nor are the rules here useful for users of react. If you want to lint your react code, try <https://github.com/yannickcr/eslint-plugin-react>.

**If you modify this rule, you must re-run `npm install ./eslint-rules` for it to take effect.**
7 changes: 7 additions & 0 deletions eslint-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
rules: {
'warning-and-invariant-args': require('./warning-and-invariant-args'),
},
};
4 changes: 4 additions & 0 deletions eslint-rules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "eslint-plugin-react-internal",
"version": "0.0.0"
}
2 changes: 1 addition & 1 deletion grunt/tasks/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function() {
var done = this.async();
grunt.util.spawn({
cmd: 'node_modules/.bin/eslint',
args: ['.', '--rulesdir=eslint-rules'],
args: ['.'],
opts: {stdio: 'inherit'}, // allows colors to passthrough
}, function(err, result, code) {
if (err) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"es5-shim": "^4.0.0",
"eslint": "^0.21.2",
"eslint-plugin-react": "^2.5.0",
"eslint-plugin-react-internal": "file:eslint-rules",
"eslint-tester": "^0.7.0",
"grunt": "~0.4.2",
"grunt-cli": "^0.1.13",
Expand Down

5 comments on commit 30cce21

@fabiomcosta
Copy link
Contributor

Choose a reason for hiding this comment

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

I've got linting to work with the instructions found at eslint-rules/README.md, but I when I do npm install . I get a 'eslint-plugin-react-internal' is not in the npm registry. error :/

@zpao
Copy link
Member

@zpao zpao commented on 30cce21 Sep 23, 2015

Choose a reason for hiding this comment

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

Just do npm install from the root of react.

@fabiomcosta
Copy link
Contributor

Choose a reason for hiding this comment

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

@zpao I get the same error with npm install

@zpao
Copy link
Member

@zpao zpao commented on 30cce21 Sep 23, 2015

Choose a reason for hiding this comment

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

Probably need to upgrade your npm then, I'm guessing you're on ~1.4. 2.0+ understands file: values. I guess having our version checks (to ensure you have the right versions of node and npm) as postinstall hooks don't work when the install fails…

@fabiomcosta
Copy link
Contributor

Choose a reason for hiding this comment

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

@zpao that worked, thank you! (I thought I had updated my npm before, but... surprise!)

Please sign in to comment.