Skip to content

Commit 21612d2

Browse files
committed
[BREAKING] ES2015ify and require Node.js >=4
ESLint now requires Node.js >=4, so no point in us supporting lower. http://eslint.org/blog/2016/07/eslint-v3.0.0-released#requires-nodejs-4-or-higher
1 parent e5056fc commit 21612d2

File tree

9 files changed

+94
-102
lines changed

9 files changed

+94
-102
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
language: node_js
22
node_js:
33
- '6'
4-
- '5'
54
- '4'
6-
- '0.12'
7-
- '0.10'
85
before_install:
96
- npm i -g npm
107
after_success: npm run coveralls

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"engines": {
25-
"node": ">=0.10.0"
25+
"node": ">=4"
2626
},
2727
"scripts": {
2828
"test": "xo && nyc ava",
@@ -59,5 +59,8 @@
5959
},
6060
"peerDependencies": {
6161
"eslint": ">=2"
62+
},
63+
"xo": {
64+
"esnext": true
6265
}
6366
}

rules/catch-error-name.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
// Matches someObj.then([FunctionExpression | ArrowFunctionExpression])
3+
// matches someObj.then([FunctionExpression | ArrowFunctionExpression])
44
function isLintablePromiseCatch(node) {
5-
var callee = node.callee;
5+
const callee = node.callee;
66

77
if (callee.type !== 'MemberExpression') {
88
return false;
99
}
1010

11-
var property = callee.property;
11+
const property = callee.property;
1212

1313
if (property.type !== 'Identifier' || property.name !== 'catch') {
1414
return false;
@@ -18,16 +18,15 @@ function isLintablePromiseCatch(node) {
1818
return false;
1919
}
2020

21-
var arg0 = node.arguments[0];
21+
const arg0 = node.arguments[0];
2222

2323
return arg0.type === 'FunctionExpression' || arg0.type === 'ArrowFunctionExpression';
2424
}
2525

2626
module.exports = function (context) {
27-
var opts = context.options[0];
28-
var name = (opts && opts.name) || 'err';
29-
30-
var stack = [];
27+
const opts = context.options[0];
28+
const name = (opts && opts.name) || 'err';
29+
const stack = [];
3130

3231
function push(value) {
3332
if (stack.length === 1) {
@@ -40,28 +39,28 @@ module.exports = function (context) {
4039
function popAndReport(node) {
4140
if (!stack.pop()) {
4241
context.report({
43-
node: node,
44-
message: 'The catch parameter should be named `' + name + '`.'
42+
node,
43+
message: `The catch parameter should be named \`${name}\`.`
4544
});
4645
}
4746
}
4847

4948
return {
50-
'CallExpression': function (node) {
49+
'CallExpression': node => {
5150
if (isLintablePromiseCatch(node)) {
52-
var params = node.arguments[0].params;
51+
const params = node.arguments[0].params;
5352
push(params.length === 0 || params[0].name === name);
5453
}
5554
},
56-
'CallExpression:exit': function (node) {
55+
'CallExpression:exit': node => {
5756
if (isLintablePromiseCatch(node)) {
5857
popAndReport(node.arguments[0].params[0]);
5958
}
6059
},
61-
'CatchClause': function (node) {
60+
'CatchClause': node => {
6261
push(node.param.name === name);
6362
},
64-
'CatchClause:exit': function (node) {
63+
'CatchClause:exit': node => {
6564
popAndReport(node.param);
6665
}
6766
};

rules/filename-case.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
'use strict';
2-
var path = require('path');
3-
var camelCase = require('lodash.camelcase');
4-
var kebabCase = require('lodash.kebabcase');
5-
var snakeCase = require('lodash.snakecase');
6-
var upperfirst = require('lodash.upperfirst');
2+
const path = require('path');
3+
const camelCase = require('lodash.camelcase');
4+
const kebabCase = require('lodash.kebabcase');
5+
const snakeCase = require('lodash.snakecase');
6+
const upperfirst = require('lodash.upperfirst');
77

8-
var pascalCase = function (str) {
9-
return upperfirst(camelCase(str));
10-
};
11-
12-
var numberRegex = /(\d+)/;
13-
var PLACEHOLDER = '\uFFFF\uFFFF\uFFFF';
14-
var PLACEHOLDER_REGEX = new RegExp(PLACEHOLDER, 'i');
8+
const pascalCase = str => upperfirst(camelCase(str));
9+
const numberRegex = /(\d+)/;
10+
const PLACEHOLDER = '\uFFFF\uFFFF\uFFFF';
11+
const PLACEHOLDER_REGEX = new RegExp(PLACEHOLDER, 'i');
1512

1613
function ignoreNumbers(fn) {
17-
return function (string) {
18-
var stack = [];
19-
var execResult = numberRegex.exec(string);
14+
return str => {
15+
const stack = [];
16+
let execResult = numberRegex.exec(str);
17+
2018
while (execResult) {
2119
stack.push(execResult[0]);
22-
string = string.replace(execResult[0], PLACEHOLDER);
23-
execResult = numberRegex.exec(string);
20+
str = str.replace(execResult[0], PLACEHOLDER);
21+
execResult = numberRegex.exec(str);
2422
}
2523

26-
var withCase = fn(string);
24+
let withCase = fn(str);
25+
2726
while (stack.length > 0) {
2827
withCase = withCase.replace(PLACEHOLDER_REGEX, stack.shift());
2928
}
@@ -32,7 +31,7 @@ function ignoreNumbers(fn) {
3231
};
3332
}
3433

35-
var cases = {
34+
const cases = {
3635
camelCase: {
3736
fn: camelCase,
3837
name: 'camel case'
@@ -58,35 +57,35 @@ function fixFilename(chosenCase, filename) {
5857
.join('.');
5958
}
6059

61-
var leadingUnserscoresRegex = /^(_+)(.*)$/;
60+
const leadingUnserscoresRegex = /^(_+)(.*)$/;
6261
function splitFilename(filename) {
63-
var res = leadingUnserscoresRegex.exec(filename);
62+
const res = leadingUnserscoresRegex.exec(filename);
6463
return {
6564
leading: (res && res[1]) || '',
6665
trailing: (res && res[2]) || filename
6766
};
6867
}
6968

70-
module.exports = function (context) {
71-
var chosenCase = cases[context.options[0].case || 'camelCase'];
72-
var filenameWithExt = context.getFilename();
69+
module.exports = context => {
70+
const chosenCase = cases[context.options[0].case || 'camelCase'];
71+
const filenameWithExt = context.getFilename();
7372

7473
if (filenameWithExt === '<text>') {
7574
return {};
7675
}
7776

7877
return {
79-
Program: function (node) {
80-
var extension = path.extname(filenameWithExt);
81-
var filename = path.basename(filenameWithExt, extension);
82-
var splitName = splitFilename(filename);
83-
var fixedFilename = fixFilename(chosenCase, splitName.trailing);
78+
Program: node => {
79+
const extension = path.extname(filenameWithExt);
80+
const filename = path.basename(filenameWithExt, extension);
81+
const splitName = splitFilename(filename);
82+
const fixedFilename = fixFilename(chosenCase, splitName.trailing);
83+
const renameFilename = splitName.leading + fixedFilename + extension;
8484

8585
if (fixedFilename !== splitName.trailing) {
8686
context.report({
87-
node: node,
88-
message: 'Filename is not in ' + chosenCase.name +
89-
'. Rename it to `' + splitName.leading + fixedFilename + extension + '`.'
87+
node,
88+
message: `Filename is not in ${chosenCase.name}. Rename it to \`${renameFilename}\`.`
9089
});
9190
}
9291
}

rules/no-abusive-eslint-disable.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
'use strict';
22

3-
var disableRegex = /^eslint-disable(-next-line|-line)?($|(\s+([\w-]+))?)/;
3+
const disableRegex = /^eslint-disable(-next-line|-line)?($|(\s+([\w-]+))?)/;
44

5-
module.exports = function (context) {
6-
return {
7-
Program: function (node) {
8-
node.comments.forEach(function (comment) {
9-
var value = comment.value.trim();
10-
var res = disableRegex.exec(value);
5+
module.exports = context => ({
6+
Program: node => {
7+
node.comments.forEach(comment => {
8+
const value = comment.value.trim();
9+
const res = disableRegex.exec(value);
1110

12-
if (res && // It is a eslint-disable comment
13-
!res[2] // but it did not specify any rules
14-
) {
15-
context.report({
16-
// Can't set it at the given location as the warning
17-
// will be ignored due to the disable comment
18-
loc: {
19-
line: 0,
20-
column: 0
21-
},
22-
// So specify it in the message
23-
message: 'Specify the rules you want to disable at line {{line}}:{{column}}',
24-
data: comment.loc.start
25-
});
26-
}
27-
});
28-
}
29-
};
30-
};
11+
if (res && // It's a eslint-disable comment
12+
!res[2] // but it did not specify any rules
13+
) {
14+
context.report({
15+
// Can't set it at the given location as the warning
16+
// will be ignored due to the disable comment
17+
loc: {
18+
line: 0,
19+
column: 0
20+
},
21+
// So specify it in the message
22+
message: 'Specify the rules you want to disable at line {{line}}:{{column}}',
23+
data: comment.loc.start
24+
});
25+
}
26+
});
27+
}
28+
});

rules/no-process-exit.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use strict';
2-
module.exports = function (context) {
3-
var startsWithHashBang = context.getSourceCode().lines[0].indexOf('#!') === 0;
2+
module.exports = context => {
3+
const startsWithHashBang = context.getSourceCode().lines[0].indexOf('#!') === 0;
44

55
if (startsWithHashBang) {
66
return {};
77
}
88

99
return {
10-
CallExpression: function (node) {
11-
var callee = node.callee;
10+
CallExpression: node => {
11+
const callee = node.callee;
1212

1313
if (callee.type === 'MemberExpression' && callee.object.name === 'process' && callee.property.name === 'exit') {
1414
context.report({
15-
node: node,
15+
node,
1616
message: 'Only use `process.exit()` in CLI apps. Throw an error instead.'
1717
});
1818
}

rules/throw-new-error.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var errorTypes = [
3+
const errorTypes = [
44
'Error',
55
'EvalError',
66
'RangeError',
@@ -10,21 +10,17 @@ var errorTypes = [
1010
'URIError'
1111
];
1212

13-
module.exports = function (context) {
14-
return {
15-
ThrowStatement: function (node) {
16-
var arg = node.argument;
17-
var error = arg.callee;
13+
module.exports = context => ({
14+
ThrowStatement: node => {
15+
const arg = node.argument;
16+
const error = arg.callee;
1817

19-
if (arg.type === 'CallExpression' && errorTypes.indexOf(error.name) !== -1) {
20-
context.report({
21-
node: node,
22-
message: 'Use `new` when throwing an error.',
23-
fix: function (fixer) {
24-
return fixer.insertTextBefore(error, 'new ');
25-
}
26-
});
27-
}
18+
if (arg.type === 'CallExpression' && errorTypes.indexOf(error.name) !== -1) {
19+
context.report({
20+
node,
21+
message: 'Use `new` when throwing an error.',
22+
fix: fixer => fixer.insertTextBefore(error, 'new ')
23+
});
2824
}
29-
};
30-
};
25+
}
26+
});

test/catch-error-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const ruleTester = avaRuleTester(test, {
1010

1111
function testCase(code, name, error) {
1212
return {
13-
code: code,
14-
options: name && [{name: name}],
13+
code,
14+
options: name && [{name}],
1515
errors: error && [{ruleId: 'catch-error-name'}]
1616
};
1717
}

test/filename-case.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const ruleTester = avaRuleTester(test, {
1111
function testCase(filename, chosenCase, errorMessage) {
1212
return {
1313
code: 'foo()',
14-
filename: filename,
14+
filename,
1515
options: [{case: chosenCase}],
1616
errors: errorMessage && [{
1717
ruleId: 'filename-case',

0 commit comments

Comments
 (0)