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

Support extends #4

Merged
merged 13 commits into from
Mar 19, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
"contributions": [
"test"
]
},
{
"login": "ta2edchimp",
"name": "Andreas Windt",
"avatar_url": "https://avatars1.githubusercontent.com/u/262436?v=3",
"html_url": "https://twitter.com/ta2edchimp",
"contributions": [
"code", "test"
]
Copy link
Contributor

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.

Copy link
Owner

Choose a reason for hiding this comment

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

👍

}
]
}
28 changes: 23 additions & 5 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Copy link
Owner

Choose a reason for hiding this comment

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

Should this comment be updated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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).

Copy link
Owner

Choose a reason for hiding this comment

The 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,
Copy link
Owner

Choose a reason for hiding this comment

The 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
}
14 changes: 11 additions & 3 deletions test/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let rules = []
const processCwd = process.cwd
const processExit = process.exit
const consoleLog = console.log // eslint-disable-line no-console
const specifiedFile = './fixtures/.eslintrc'
const noSpecifiedFile = './fixtures/no-path'
const specifiedFile = './fixtures/.eslintrc.js'
const mainFile = path.join(process.cwd(), specifiedFile)
const extendingFile = './fixtures/extending-config.json'
const indexStub = {
'./index': () => rules,
}
Expand Down Expand Up @@ -38,7 +40,7 @@ test('no new rule and relative path', () => {
})

test('no new rule and no path', () => {
process.cwd = () => mainFile
process.cwd = () => noSpecifiedFile
proxyquire('../bin', indexStub)
})

Expand All @@ -56,6 +58,12 @@ test('new rule and relative path', () => {

test('new rule and no path', () => {
rules = ['foo', 'bar', 'baz']
process.cwd = () => mainFile
process.cwd = () => noSpecifiedFile
proxyquire('../bin', indexStub)
})

test('new rule (extending)', () => {
rules = ['comma-dangle', 'no-console', 'no-alert']
process.argv[2] = extendingFile
proxyquire('../bin', indexStub)
})
2 changes: 1 addition & 1 deletion test/fixtures/.eslintrc → test/fixtures/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
rules: {
foo: true,
"no-console": [2],
}
}
5 changes: 5 additions & 0 deletions test/fixtures/base-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rules:
Copy link
Owner

Choose a reason for hiding this comment

The 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
6 changes: 6 additions & 0 deletions test/fixtures/extending-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./base-config.yml",
"rules": {
"comma-dangle": [2, "never"]
}
}
11 changes: 11 additions & 0 deletions test/fixtures/no-path/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The 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]
}
}
}