-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support extends
#4
Changes from 5 commits
18b8aae
cecadda
5a8859a
c1205f9
297c510
5277e66
14a9de7
ffb0f16
212dc85
e843a84
3fb35ab
7bb5d07
519b643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,29 +5,47 @@ | |
// Prints rules recognized by ESLint that don't appear in the given config | ||
// preset. It helps with upgrading the preset when new ESLint gets released. | ||
var path = require('path') | ||
var eslint = require('eslint') | ||
var isAbsolute = require('path-is-absolute') | ||
var findNewRules = require('./index') | ||
|
||
var currentRules = Object.keys(getConfig().rules) | ||
var currentRules = getRules() | ||
var newRules = findNewRules(currentRules) | ||
|
||
if (newRules.length) { | ||
console.log('New rules to add to the config: ' + newRules.join(', ') + '.') // eslint-disable-line no-console | ||
process.exit(1) | ||
} | ||
|
||
function getConfig() { | ||
function getConfigFile() { | ||
var specifiedFile = process.argv[2] | ||
if (specifiedFile) { | ||
// this is being called like: eslint-find-new-rules eslint-config-mgol | ||
if (isAbsolute(specifiedFile)) { | ||
return require(specifiedFile) | ||
return specifiedFile | ||
} else { | ||
return require(path.join(process.cwd(), specifiedFile)) | ||
return path.join(process.cwd(), specifiedFile) | ||
} | ||
} else { | ||
// this is not being called with an arg. Use the package.json `main` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this comment be updated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I'm currently about to rewrite that part anyway (to restore the desired behavior described in the comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, that's what I thought. Thanks! |
||
return require(process.cwd()) | ||
return path.join(process.cwd(), 'package.json') | ||
} | ||
} | ||
|
||
function getConfig(file) { | ||
var cliEngine = new eslint.CLIEngine({ | ||
// ignore any config applicable depending on the location on the filesystem | ||
useEslintrc: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome that this is possible 👍 |
||
// point to the particular config | ||
configFile: file, | ||
}) | ||
var config = cliEngine.getConfigForFile(file) | ||
return config | ||
} | ||
|
||
function getRules() { | ||
var configFile = getConfigFile() | ||
var config = getConfig(configFile) | ||
var rules = Object.keys(config.rules) | ||
return rules | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
rules: { | ||
foo: true, | ||
"no-console": [2], | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rules: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that you're using yml and json 👍 |
||
no-console: | ||
- 2 | ||
no-alert: | ||
- 2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./base-config.yml", | ||
"rules": { | ||
"comma-dangle": [2, "never"] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and a package.json :-) |
||
"name": "fake-project", | ||
"version": "0.0.0", | ||
"description": "Simulating a project's package.json.", | ||
"private": true, | ||
"eslintConfig": { | ||
"rules": { | ||
"no-console": [2] | ||
} | ||
} | ||
} |
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.
You might want to add "docs" too.
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.
👍