Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 27, 2018
1 parent 6254110 commit d1eb47c
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,8 +1,8 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
before_install:
- npm install --global npm
after_success: npm run coveralls
2 changes: 1 addition & 1 deletion appveyor.yml
@@ -1,8 +1,8 @@
environment:
matrix:
- nodejs_version: '10'
- nodejs_version: '8'
- nodejs_version: '6'
- nodejs_version: '4'
install:
- ps: Install-Product node $env:nodejs_version
- npm install --global npm@latest
Expand Down
8 changes: 2 additions & 6 deletions config/plugins.js
Expand Up @@ -5,8 +5,7 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true
jsx: true
}
},
// -- end repeat
Expand Down Expand Up @@ -81,9 +80,6 @@ module.exports = {
// 'node/shebang': 'error',
'node/no-deprecated-api': 'error',
// Disabled because it causes too much churn and will be moot when we switch to ES2015 modules
// 'node/exports-style': ['error', 'module.exports'],
// Disabled by default (overrides `plugin:unicorn/recommended`), will be enabled if supported by the Node.js version
'unicorn/prefer-spread': 'off',
'unicorn/no-new-buffer': 'off'
// 'node/exports-style': ['error', 'module.exports']
}
};
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -43,7 +43,7 @@ module.exports.lintText = (str, opts) => {
opts = optionsManager.preprocess(opts);

if (opts.overrides && opts.overrides.length > 0) {
const overrides = opts.overrides;
const {overrides} = opts;
delete opts.overrides;

const filename = path.relative(opts.cwd, opts.filename);
Expand Down Expand Up @@ -98,15 +98,15 @@ module.exports.lintFiles = (patterns, opts) => {
if (!isEmptyPatterns) {
paths = paths.filter(filePath => {
const ext = path.extname(filePath).replace('.', '');
return opts.extensions.indexOf(ext) !== -1;
return opts.extensions.includes(ext);
});
}

if (!(opts.overrides && opts.overrides.length > 0)) {
return runEslint(paths, opts);
}

const overrides = opts.overrides;
const {overrides} = opts;
delete opts.overrides;

const grouped = optionsManager.groupConfigs(paths, opts, overrides);
Expand Down
4 changes: 2 additions & 2 deletions lib/open-report.js
Expand Up @@ -4,7 +4,7 @@ const openEditor = require('open-editor');
const sortResults = (a, b) => a.errorCount + b.errorCount > 0 ? (a.errorCount - b.errorCount) : (a.warningCount - b.warningCount);

const resultToFile = result => {
const message = result.messages
const [message] = result.messages
.sort((a, b) => {
if (a.severity < b.severity) {
return 1;
Expand All @@ -23,7 +23,7 @@ const resultToFile = result => {
}

return 0;
})[0];
});

return {
file: result.filePath,
Expand Down
24 changes: 5 additions & 19 deletions lib/options-manager.js
Expand Up @@ -57,8 +57,8 @@ const DEFAULT_CONFIG = {
* {
* 'plugin/rule': {
* '6.0.0': ['error', {prop: 'node-6-conf'}],
* '8.0.0': ['error', {prop: 'node-8-conf'}]
* }
* '8.0.0': ['error', {prop: 'node-8-conf'}]
* }
* }
*```
* With `engines.node` set to `>=4` the rule `plugin/rule` will not be used.
Expand All @@ -68,18 +68,6 @@ const DEFAULT_CONFIG = {
const ENGINE_RULES = {
'promise/prefer-await-to-then': {
'7.6.0': 'error'
},
'prefer-rest-params': {
'6.0.0': 'error'
},
'unicorn/prefer-spread': {
'5.0.0': 'error'
},
'prefer-destructuring': {
'6.0.0': ['error', {array: true, object: true}]
},
'unicorn/no-new-buffer': {
'5.10.0': 'error'
}
};

Expand Down Expand Up @@ -133,9 +121,7 @@ const mergeWithPkgConf = opts => {
return Object.assign({}, conf, {engines}, opts);
};

const normalizeSpaces = opts => {
return typeof opts.space === 'number' ? opts.space : 2;
};
const normalizeSpaces = opts => typeof opts.space === 'number' ? opts.space : 2;

const mergeWithPrettierConf = (opts, prettierOpts) => {
if ((opts.semicolon === true && prettierOpts.semi === false) ||
Expand Down Expand Up @@ -189,7 +175,7 @@ const buildConfig = opts => {

if (opts.engines && opts.engines.node && semver.validRange(opts.engines.node)) {
for (const rule of Object.keys(ENGINE_RULES)) {
// Use the rule value for the highest version that is lower or equal to the oldest version of Node supported
// Use the rule value for the highest version that is lower or equal to the oldest version of Node.js supported
for (const minVersion of Object.keys(ENGINE_RULES[rule]).sort(semver.compare)) {
if (!semver.intersects(opts.engines.node, `<${minVersion}`)) {
config.rules[rule] = ENGINE_RULES[rule][minVersion];
Expand Down Expand Up @@ -316,7 +302,7 @@ const findApplicableOverrides = (path, overrides) => {
const mergeApplicableOverrides = (baseOptions, applicableOverrides) => {
applicableOverrides = applicableOverrides.map(override => normalizeOpts(override));
const overrides = [emptyOptions(), baseOptions].concat(applicableOverrides, mergeFn);
return mergeWith.apply(null, overrides);
return mergeWith(...overrides);
};

// Creates grouped sets of merged options together with the paths they apply to.
Expand Down
5 changes: 2 additions & 3 deletions main.js
Expand Up @@ -115,8 +115,7 @@ const cli = meow(`

updateNotifier({pkg: cli.pkg}).notify();

const input = cli.input;
const opts = cli.flags;
const {input, flags: opts} = cli;

const log = report => {
const reporter = opts.reporter ? xo.getFormatter(opts.reporter) : formatterPretty;
Expand All @@ -137,7 +136,7 @@ if (opts.nodeVersion) {
} else if (semver.validRange(opts.nodeVersion)) {
opts.engines = {node: opts.nodeVersion};
} else {
console.error('The `node-engine` option must be a valid semver range (for example `>=4`)');
console.error('The `node-engine` option must be a valid semver range (for example `>=6`)');
process.exit(1);
}
}
Expand Down
18 changes: 9 additions & 9 deletions package.json
Expand Up @@ -11,7 +11,7 @@
},
"bin": "cli.js",
"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"test": "node main.js && eslint . && nyc ava",
Expand Down Expand Up @@ -53,9 +53,9 @@
"dependencies": {
"arrify": "^1.0.1",
"debug": "^3.1.0",
"eslint": "^4.17.0",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-config-xo": "^0.20.0",
"eslint-config-xo": "^0.22.0",
"eslint-formatter-pretty": "^1.3.0",
"eslint-plugin-ava": "^4.5.0",
"eslint-plugin-import": "^2.8.0",
Expand All @@ -64,21 +64,21 @@
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-unicorn": "^4.0.1",
"get-stdin": "^5.0.1",
"get-stdin": "^6.0.0",
"globby": "^8.0.0",
"has-flag": "^3.0.0",
"lodash.isequal": "^4.5.0",
"lodash.mergewith": "^4.6.1",
"meow": "^4.0.0",
"meow": "^5.0.0",
"multimatch": "^2.1.0",
"open-editor": "^1.2.0",
"path-exists": "^3.0.0",
"pkg-conf": "^2.1.0",
"prettier": "~1.11.1",
"prettier": "^1.12.1",
"resolve-cwd": "^2.0.0",
"resolve-from": "^4.0.0",
"semver": "^5.5.0",
"slash": "^1.0.0",
"slash": "^2.0.0",
"update-notifier": "^2.3.0",
"xo-init": "^0.7.0"
},
Expand All @@ -87,10 +87,10 @@
"coveralls": "^3.0.0",
"eslint-config-xo-react": "^0.16.0",
"eslint-plugin-react": "^7.6.1",
"execa": "^0.9.0",
"execa": "^0.10.0",
"nyc": "^11.4.1",
"pify": "^3.0.0",
"proxyquire": "^1.8.0",
"proxyquire": "^2.0.1",
"temp-write": "^3.4.0"
},
"eslintConfig": {
Expand Down
26 changes: 13 additions & 13 deletions test/lint-text.js
Expand Up @@ -10,7 +10,7 @@ const readFile = pify(fs.readFile);
const hasRule = (results, ruleId) => results[0].messages.some(x => x.ruleId === ruleId);

test('.lintText()', t => {
const results = fn.lintText(`'use strict'\nconsole.log('unicorn');\n`).results;
const {results} = fn.lintText(`'use strict'\nconsole.log('unicorn');\n`);
t.true(hasRule(results, 'semi'));
});

Expand Down Expand Up @@ -78,34 +78,34 @@ test('`ignores` option without filename', t => {
});

test('JSX support', t => {
const results = fn.lintText('const app = <div className="appClass">Hello, React!</div>;\n').results;
const {results} = fn.lintText('const app = <div className="appClass">Hello, React!</div>;\n');
t.true(hasRule(results, 'no-unused-vars'));
});

test('plugin support', t => {
const results = fn.lintText('var React;\nReact.render(<App/>);\n', {
const {results} = fn.lintText('var React;\nReact.render(<App/>);\n', {
plugins: ['react'],
rules: {'react/jsx-no-undef': 'error'}
}).results;
});
t.true(hasRule(results, 'react/jsx-no-undef'));
});

test('prevent use of extended native objects', t => {
const results = fn.lintText('[].unicorn();\n').results;
const {results} = fn.lintText('[].unicorn();\n');
t.true(hasRule(results, 'no-use-extend-native/no-use-extend-native'));
});

test('extends support', t => {
const results = fn.lintText('var React;\nReact.render(<App/>);\n', {
const {results} = fn.lintText('var React;\nReact.render(<App/>);\n', {
extends: 'xo-react'
}).results;
});
t.true(hasRule(results, 'react/jsx-no-undef'));
});

test('extends support with `esnext` option', t => {
const results = fn.lintText('import path from \'path\';\nlet React;\nReact.render(<App/>);\n', {
const {results} = fn.lintText('import path from \'path\';\nlet React;\nReact.render(<App/>);\n', {
extends: 'xo-react'
}).results;
});
t.true(hasRule(results, 'react/jsx-no-undef'));
});

Expand All @@ -124,22 +124,22 @@ test('disable style rules when `prettier` option is enabled', t => {
});

test('extends `react` support with `prettier` option', t => {
const results = fn.lintText('<Hello name={ firstname } />;\n', {extends: 'xo-react', prettier: true}).results;
const {results} = fn.lintText('<Hello name={ firstname } />;\n', {extends: 'xo-react', prettier: true});
// `react/jsx-curly-spacing` is disabled by `eslint-config-prettier`
t.false(hasRule(results, 'react/jsx-curly-spacing'));
// `prettier/prettier` is enabled
t.true(hasRule(results, 'prettier/prettier'));
});

test('always use the latest ECMAScript parser so esnext syntax won\'t throw in normal mode', t => {
const results = fn.lintText('async function foo() {}\n\nfoo();\n').results;
const {results} = fn.lintText('async function foo() {}\n\nfoo();\n');
t.is(results[0].errorCount, 0);
});

test('regression test for #71', t => {
const results = fn.lintText(`const foo = { key: 'value' };\nconsole.log(foo);\n`, {
const {results} = fn.lintText(`const foo = { key: 'value' };\nconsole.log(foo);\n`, {
extends: path.join(__dirname, 'fixtures/extends.js')
}).results;
});
t.is(results[0].errorCount, 0, results[0]);
});

Expand Down
2 changes: 1 addition & 1 deletion test/main.js
Expand Up @@ -36,7 +36,7 @@ test('reporter option', async t => {
try {
await main(['--reporter=compact', filepath]);
} catch (err) {
t.true(err.stdout.indexOf('Error - ') !== -1);
t.true(err.stdout.includes('Error - '));
}
});

Expand Down
41 changes: 0 additions & 41 deletions test/options-manager.js
Expand Up @@ -227,50 +227,9 @@ test('buildConfig: engines: invalid range', t => {
t.is(config.rules['promise/prefer-await-to-then'], undefined);
});

test('buildConfig: engines: >=4', t => {
const config = manager.buildConfig({engines: {node: '>=4'}});

// Do not include rules for Node.js 5 and above
t.is(config.rules['unicorn/prefer-spread'], undefined);
// Do not include rules for Node.js 6 and above
t.is(config.rules['prefer-rest-params'], undefined);
t.is(config.rules['prefer-destructuring'], undefined);
// Do not include rules for Node.js 8 and above
t.is(config.rules['promise/prefer-await-to-then'], undefined);
});

test('buildConfig: engines: >=4.1', t => {
const config = manager.buildConfig({engines: {node: '>=5.1'}});

// Do not include rules for Node.js 5 and above
t.is(config.rules['unicorn/prefer-spread'], 'error');
// Do not include rules for Node.js 6 and above
t.is(config.rules['prefer-rest-params'], undefined);
t.is(config.rules['prefer-destructuring'], undefined);
// Do not include rules for Node.js 8 and above
t.is(config.rules['promise/prefer-await-to-then'], undefined);
});

test('buildConfig: engines: >=6', t => {
const config = manager.buildConfig({engines: {node: '>=6'}});

// Include rules for Node.js 5 and above
t.is(config.rules['unicorn/prefer-spread'], 'error');
// Include rules for Node.js 6 and above
t.is(config.rules['prefer-rest-params'], 'error');
t.deepEqual(config.rules['prefer-destructuring'], ['error', {array: true, object: true}]);
// Do not include rules for Node.js 8 and above
t.is(config.rules['promise/prefer-await-to-then'], undefined);
});

test('buildConfig: engines: >=8', t => {
const config = manager.buildConfig({engines: {node: '>=8'}});

// Include rules for Node.js 5 and above
t.is(config.rules['unicorn/prefer-spread'], 'error');
// Include rules for Node.js 6 and above
t.is(config.rules['prefer-rest-params'], 'error');
t.deepEqual(config.rules['prefer-destructuring'], ['error', {array: true, object: true}]);
// Include rules for Node.js 8 and above
t.is(config.rules['promise/prefer-await-to-then'], 'error');
});
Expand Down

0 comments on commit d1eb47c

Please sign in to comment.