-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from rogeliog/add-configs
Allow config overrides
- Loading branch information
Showing
10 changed files
with
400 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
**/node_modules | ||
build | ||
|
||
**/coverage/ | ||
integrationTests/__fixtures__/skipped/__eslint__/file.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* global hello */ | ||
const a = 1; | ||
|
||
if (a === 2) { | ||
|
5 changes: 5 additions & 0 deletions
5
integrationTests/__fixtures__/passing/jest-runner-eslint.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
cliOptions: { | ||
global: ['hello'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
const normalizeConfig = require('../normalizeConfig'); | ||
|
||
const normalizeCLIOptions = cliOptions => | ||
normalizeConfig({ cliOptions }).cliOptions; | ||
|
||
it('ignores unkown options', () => { | ||
expect(normalizeCLIOptions({ other: true })).not.toMatchObject({ | ||
other: true, | ||
}); | ||
}); | ||
|
||
it('normalizes noInlineConfig', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
allowInlineConfig: true, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ noInlineConfig: true })).toMatchObject({ | ||
allowInlineConfig: false, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ noInlineConfig: false })).toMatchObject({ | ||
allowInlineConfig: true, | ||
}); | ||
}); | ||
|
||
it('normalizes cacheLocation', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
cacheLocation: '.eslintcache', | ||
}); | ||
|
||
expect( | ||
normalizeCLIOptions({ cacheLocation: '/path/to/cache' }), | ||
).toMatchObject({ | ||
cacheLocation: '/path/to/cache', | ||
}); | ||
}); | ||
|
||
it('normalizes config', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
configFile: null, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ config: '/path/to/config' })).toMatchObject({ | ||
configFile: '/path/to/config', | ||
}); | ||
}); | ||
|
||
it('normalizes env', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
envs: [], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ env: 'mocha' })).toMatchObject({ | ||
envs: ['mocha'], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ env: ['mocha', 'browser'] })).toMatchObject({ | ||
envs: ['mocha', 'browser'], | ||
}); | ||
}); | ||
|
||
it('normalizes ext', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
extensions: ['.js'], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ ext: '.ts' })).toMatchObject({ | ||
extensions: ['.ts'], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ ext: ['.js', '.jsx', '.ts'] })).toMatchObject({ | ||
extensions: ['.js', '.jsx', '.ts'], | ||
}); | ||
}); | ||
|
||
it('normalizes fix', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
fix: false, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ fix: true })).toMatchObject({ | ||
fix: true, | ||
}); | ||
}); | ||
|
||
it('normalizes global', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
globals: [], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ global: 'it' })).toMatchObject({ | ||
globals: ['it'], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ global: ['it', 'describe'] })).toMatchObject({ | ||
globals: ['it', 'describe'], | ||
}); | ||
}); | ||
|
||
it('normalizes noIgnore', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
ignore: true, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ noIgnore: true })).toMatchObject({ | ||
ignore: false, | ||
}); | ||
}); | ||
|
||
it('normalizes ignorePath', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
ignorePath: null, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ ignorePath: '/path/to/ignore' })).toMatchObject({ | ||
ignorePath: '/path/to/ignore', | ||
}); | ||
}); | ||
|
||
it('normalizes parser', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
parser: 'espree', | ||
}); | ||
|
||
expect(normalizeCLIOptions({ parser: 'flow' })).toMatchObject({ | ||
parser: 'flow', | ||
}); | ||
}); | ||
|
||
it('normalizes parserOptions', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
parserOptions: {}, | ||
}); | ||
|
||
expect( | ||
normalizeCLIOptions({ parserOptions: { ecmaVersion: 2015 } }), | ||
).toMatchObject({ | ||
parserOptions: { ecmaVersion: 2015 }, | ||
}); | ||
}); | ||
|
||
it('normalizes plugin', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
plugins: [], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ plugin: 'prettier' })).toMatchObject({ | ||
plugins: ['prettier'], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ plugin: ['prettier'] })).toMatchObject({ | ||
plugins: ['prettier'], | ||
}); | ||
}); | ||
|
||
it('normalizes rulesdir', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
rulePaths: [], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ rulesdir: '/path/to/rules' })).toMatchObject({ | ||
rulePaths: ['/path/to/rules'], | ||
}); | ||
|
||
expect( | ||
normalizeCLIOptions({ rulesdir: ['/path/to/rules', '/other/path'] }), | ||
).toMatchObject({ | ||
rulePaths: ['/path/to/rules', '/other/path'], | ||
}); | ||
}); | ||
|
||
it('normalizes rule', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
rules: null, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ rule: ['quotes: [2, double]'] })).toMatchObject({ | ||
rules: ['quotes: [2, double]'], | ||
}); | ||
|
||
expect(normalizeCLIOptions({ rule: 'quotes: [2, double]' })).toMatchObject({ | ||
rules: ['quotes: [2, double]'], | ||
}); | ||
}); | ||
|
||
it('normalizes noEslintrc', () => { | ||
expect(normalizeCLIOptions({})).toMatchObject({ | ||
useEslintrc: true, | ||
}); | ||
|
||
expect(normalizeCLIOptions({ noEslintrc: true })).toMatchObject({ | ||
useEslintrc: false, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const normalizeConfig = require('./normalizeConfig'); | ||
const cosmiconfig = require('cosmiconfig'); | ||
|
||
const explorer = cosmiconfig('jest-runner-eslint', { sync: true }); | ||
|
||
const getESLintOptions = config => { | ||
const result = explorer.load(config.rootDir); | ||
|
||
if (result) { | ||
return normalizeConfig(result.config); | ||
} | ||
|
||
return normalizeConfig({}); | ||
}; | ||
|
||
module.exports = getESLintOptions; |
Oops, something went wrong.