eslint-plugin-unicorn 4.0.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-unicorn",
3
- "version": "4.0.3",
3
+ "version": "5.0.0",
4
4
  "description": "Various awesome ESLint rules",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/eslint-plugin-unicorn",
@@ -10,10 +10,10 @@
10
10
  "url": "sindresorhus.com"
11
11
  },
12
12
  "engines": {
13
- "node": ">=4"
13
+ "node": ">=6"
14
14
  },
15
15
  "scripts": {
16
- "test": "xo && nyc ava",
16
+ "test": "nyc ava",
17
17
  "integration": "./test/integration/test.js",
18
18
  "coveralls": "nyc report --reporter=text-lcov | coveralls"
19
19
  },
@@ -46,17 +46,17 @@
46
46
  "chalk": "^2.0.1",
47
47
  "coveralls": "^3.0.0",
48
48
  "del": "^3.0.0",
49
- "eslint": "^4.0.0",
49
+ "eslint": "^5.0.0",
50
50
  "eslint-ava-rule-tester": "^2.0.0",
51
- "execa": "^0.9.0",
52
- "listr": "^0.13.0",
53
- "nyc": "^11.0.3",
51
+ "execa": "^0.10.0",
52
+ "listr": "^0.14.1",
53
+ "nyc": "^12.0.2",
54
54
  "pify": "^3.0.0",
55
55
  "tempy": "^0.2.1",
56
56
  "xo": "*"
57
57
  },
58
58
  "peerDependencies": {
59
- "eslint": ">=4"
59
+ "eslint": ">=5.0.0"
60
60
  },
61
61
  "ava": {
62
62
  "files": [
package/readme.md CHANGED
@@ -26,7 +26,7 @@ Configure it in `package.json`.
26
26
  "es6": true
27
27
  },
28
28
  "parserOptions": {
29
- "ecmaVersion": 2017,
29
+ "ecmaVersion": 2018,
30
30
  "sourceType": "module"
31
31
  },
32
32
  "plugins": [
Binary file
@@ -4,13 +4,13 @@ const getDocsUrl = require('./utils/get-docs-url');
4
4
 
5
5
  // Matches `someObj.then([FunctionExpression | ArrowFunctionExpression])`
6
6
  function isLintablePromiseCatch(node) {
7
- const callee = node.callee;
7
+ const {callee} = node;
8
8
 
9
9
  if (callee.type !== 'MemberExpression') {
10
10
  return false;
11
11
  }
12
12
 
13
- const property = callee.property;
13
+ const {property} = callee;
14
14
 
15
15
  if (property.type !== 'Identifier' || property.name !== 'catch') {
16
16
  return false;
@@ -20,7 +20,7 @@ function isLintablePromiseCatch(node) {
20
20
  return false;
21
21
  }
22
22
 
23
- const arg0 = node.arguments[0];
23
+ const [arg0] = node.arguments;
24
24
 
25
25
  return arg0.type === 'FunctionExpression' || arg0.type === 'ArrowFunctionExpression';
26
26
  }
@@ -42,7 +42,7 @@ const create = context => {
42
42
  caughtErrorsIgnorePattern: '^_$'
43
43
  }, context.options[0]);
44
44
 
45
- const name = options.name;
45
+ const {name} = options;
46
46
  const caughtErrorsIgnorePattern = new RegExp(options.caughtErrorsIgnorePattern);
47
47
  const stack = [];
48
48
 
@@ -68,7 +68,7 @@ const create = context => {
68
68
  return {
69
69
  CallExpression: node => {
70
70
  if (isLintablePromiseCatch(node)) {
71
- const params = node.arguments[0].params;
71
+ const {params} = node.arguments[0];
72
72
 
73
73
  if (params.length > 0 && params[0].name === '_') {
74
74
  push(!astUtils.containsIdentifier('_', node.arguments[0].body));
@@ -18,10 +18,10 @@ const hasValidSuperClass = node => {
18
18
  return false;
19
19
  }
20
20
 
21
- let name = node.superClass.name;
21
+ let {name} = node.superClass;
22
22
 
23
23
  if (node.superClass.type === 'MemberExpression') {
24
- name = node.superClass.property.name;
24
+ ({name} = node.superClass.property);
25
25
  }
26
26
 
27
27
  return nameRegexp.test(name);
@@ -48,7 +48,7 @@ const customErrorDefinition = (context, node) => {
48
48
  return;
49
49
  }
50
50
 
51
- const name = node.id.name;
51
+ const {name} = node.id;
52
52
  const className = getClassName(name);
53
53
 
54
54
  if (name !== className) {
@@ -58,8 +58,7 @@ const customErrorDefinition = (context, node) => {
58
58
  });
59
59
  }
60
60
 
61
- const body = node.body.body;
62
-
61
+ const {body} = node.body;
63
62
  const constructor = body.find(x => x.kind === 'constructor');
64
63
 
65
64
  if (!constructor) {
@@ -36,13 +36,14 @@ function checkZeroType(context, node) {
36
36
  }
37
37
 
38
38
  function checkNonZeroType(context, node, type) {
39
- const value = node.right.value;
40
- const operator = node.operator;
39
+ const {value} = node.right;
40
+ const {operator} = node;
41
41
 
42
42
  switch (type) {
43
43
  case 'greater-than':
44
- if ((operatorTypes.gte.indexOf(operator) !== -1 && value === 1) ||
45
- (operatorTypes.ne.indexOf(operator) !== -1 && value === 0)
44
+ if (
45
+ (operatorTypes.gte.includes(operator) && value === 1) ||
46
+ (operatorTypes.ne.includes(operator) && value === 0)
46
47
  ) {
47
48
  reportError(
48
49
  context,
@@ -57,8 +58,9 @@ function checkNonZeroType(context, node, type) {
57
58
  }
58
59
  break;
59
60
  case 'greater-than-or-equal':
60
- if ((operatorTypes.gt.indexOf(operator) !== -1 && value === 0) ||
61
- (operatorTypes.ne.indexOf(operator) !== -1 && value === 0)
61
+ if (
62
+ (operatorTypes.gt.includes(operator) && value === 0) ||
63
+ (operatorTypes.ne.includes(operator) && value === 0)
62
64
  ) {
63
65
  reportError(
64
66
  context,
@@ -73,8 +75,9 @@ function checkNonZeroType(context, node, type) {
73
75
  }
74
76
  break;
75
77
  case 'not-equal':
76
- if ((operatorTypes.gt.indexOf(operator) !== -1 && value === 0) ||
77
- (operatorTypes.gte.indexOf(operator) !== -1 && value === 1)
78
+ if (
79
+ (operatorTypes.gt.includes(operator) && value === 0) ||
80
+ (operatorTypes.gte.includes(operator) && value === 1)
78
81
  ) {
79
82
  reportError(
80
83
  context,
@@ -133,6 +136,9 @@ const create = context => {
133
136
  return {
134
137
  IfStatement: node => {
135
138
  checkExpression(context, node.test);
139
+ },
140
+ ConditionalExpression: node => {
141
+ checkExpression(context, node.test);
136
142
  }
137
143
  };
138
144
  };
@@ -36,7 +36,7 @@ const disallowNew = new Set([
36
36
  const create = context => {
37
37
  return {
38
38
  CallExpression: node => {
39
- const name = node.callee.name;
39
+ const {name} = node.callee;
40
40
 
41
41
  if (enforceNew.has(name)) {
42
42
  context.report({
@@ -47,7 +47,7 @@ const create = context => {
47
47
  }
48
48
  },
49
49
  NewExpression: node => {
50
- const name = node.callee.name;
50
+ const {name} = node.callee;
51
51
 
52
52
  if (disallowNew.has(name)) {
53
53
  context.report({
@@ -5,11 +5,12 @@ const disableRegex = /^eslint-disable(-next-line|-line)?($|(\s+(@[\w-]+\/[\w-]+\
5
5
 
6
6
  const create = context => ({
7
7
  Program: node => {
8
- node.comments.forEach(comment => {
8
+ for (const comment of node.comments) {
9
9
  const value = comment.value.trim();
10
10
  const res = disableRegex.exec(value);
11
11
 
12
- if (res && // It's a eslint-disable comment
12
+ if (
13
+ res && // It's a eslint-disable comment
13
14
  !res[2] // But it did not specify any rules
14
15
  ) {
15
16
  context.report({
@@ -24,7 +25,7 @@ const create = context => ({
24
25
  data: comment.loc.start
25
26
  });
26
27
  }
27
- });
28
+ }
28
29
  }
29
30
  });
30
31
 
@@ -34,7 +34,7 @@ const fix = (context, node) => {
34
34
  const create = context => ({
35
35
  'CallExpression[callee.object.name!="Promise"]': node => {
36
36
  if (isIteratorMethod(node) && hasFunctionArgument(node)) {
37
- const arg = node.arguments[0];
37
+ const [arg] = node.arguments;
38
38
 
39
39
  context.report({
40
40
  node: arg,
@@ -12,7 +12,7 @@ const create = context => {
12
12
 
13
13
  return {
14
14
  CallExpression: node => {
15
- const callee = node.callee;
15
+ const {callee} = node;
16
16
 
17
17
  if (callee.type === 'MemberExpression' && callee.object.name === 'process') {
18
18
  if (callee.property.name === 'on' || callee.property.name === 'once') {
@@ -32,7 +32,7 @@ const create = context => {
32
32
  let flags = null;
33
33
 
34
34
  if (hasRegExp) {
35
- pattern = args[0].regex.pattern;
35
+ ({pattern} = args[0].regex);
36
36
  flags = args[1] && args[1].type === 'Literal' ? args[1].value : args[0].regex.flags;
37
37
  } else {
38
38
  pattern = args[0].value;
@@ -2,7 +2,7 @@
2
2
  const getDocsUrl = require('./utils/get-docs-url');
3
3
 
4
4
  const isArrayFrom = node => {
5
- const callee = node.callee;
5
+ const {callee} = node;
6
6
  return (
7
7
  callee.type === 'MemberExpression' &&
8
8
  callee.object.type === 'Identifier' &&
@@ -11,7 +11,7 @@ const isSimpleString = string => doesNotContain(
11
11
  const create = context => {
12
12
  return {
13
13
  CallExpression(node) {
14
- const callee = node.callee;
14
+ const {callee} = node;
15
15
  const prop = callee.property;
16
16
 
17
17
  if (!(prop && callee.type === 'MemberExpression')) {
@@ -22,9 +22,9 @@ const create = context => {
22
22
 
23
23
  let regex;
24
24
  if (prop.name === 'test' && callee.object.regex) {
25
- regex = callee.object.regex;
25
+ ({regex} = callee.object);
26
26
  } else if (prop.name === 'match' && args && args[0] && args[0].regex) {
27
- regex = args[0].regex;
27
+ ({regex} = args[0]);
28
28
  } else {
29
29
  return;
30
30
  }
@@ -33,7 +33,7 @@ const create = context => {
33
33
  return;
34
34
  }
35
35
 
36
- const pattern = regex.pattern;
36
+ const {pattern} = regex;
37
37
  if (pattern.startsWith('^') && isSimpleString(pattern.slice(1))) {
38
38
  context.report({
39
39
  node,
@@ -8,7 +8,7 @@ const create = context => {
8
8
  return {
9
9
  'Literal[regex]': node => {
10
10
  const oldPattern = node.regex.pattern;
11
- const flags = node.regex.flags;
11
+ const {flags} = node.regex;
12
12
 
13
13
  const newPattern = cleanRegexp(oldPattern, flags);
14
14