eslint-plugin-no-jquery 2.7.0 → 3.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.
Files changed (50) hide show
  1. package/README.md +2 -2
  2. package/README.md.template +1 -1
  3. package/package.json +12 -9
  4. package/src/.eslintrc.js +17 -0
  5. package/src/all-methods.js +2 -1
  6. package/src/index.js +4 -1
  7. package/src/rules/no-ajax-events.js +26 -28
  8. package/src/rules/no-ajax.js +1 -1
  9. package/src/rules/no-and-self.js +1 -3
  10. package/src/rules/no-animate-toggle.js +3 -3
  11. package/src/rules/no-animate.js +28 -30
  12. package/src/rules/no-append-html.js +18 -20
  13. package/src/rules/no-class-state.js +16 -18
  14. package/src/rules/no-class.js +1 -1
  15. package/src/rules/no-constructor-attributes.js +21 -23
  16. package/src/rules/no-data.js +1 -1
  17. package/src/rules/no-deferred.js +2 -2
  18. package/src/rules/no-error.js +1 -3
  19. package/src/rules/no-escape-selector.js +1 -3
  20. package/src/rules/no-event-shorthand.js +3 -3
  21. package/src/rules/no-extend.js +28 -26
  22. package/src/rules/no-fade.js +1 -1
  23. package/src/rules/no-fx-interval.js +13 -15
  24. package/src/rules/no-global-selector.js +39 -41
  25. package/src/rules/no-is-array.js +1 -3
  26. package/src/rules/no-is-function.js +1 -1
  27. package/src/rules/no-jquery-constructor.js +13 -15
  28. package/src/rules/no-load-shorthand.js +17 -19
  29. package/src/rules/no-noop.js +1 -3
  30. package/src/rules/no-now.js +1 -3
  31. package/src/rules/no-on-ready.js +29 -34
  32. package/src/rules/no-other-methods.js +19 -21
  33. package/src/rules/no-other-utils.js +18 -20
  34. package/src/rules/no-parse-html-literal.js +60 -67
  35. package/src/rules/no-parse-json.js +1 -3
  36. package/src/rules/no-parse-xml.js +1 -1
  37. package/src/rules/no-prop.js +1 -1
  38. package/src/rules/no-proxy.js +1 -1
  39. package/src/rules/no-ready-shorthand.js +1 -1
  40. package/src/rules/no-ready.js +9 -11
  41. package/src/rules/no-serialize.js +1 -1
  42. package/src/rules/no-size.js +1 -3
  43. package/src/rules/no-sizzle.js +5 -5
  44. package/src/rules/no-slide.js +1 -1
  45. package/src/rules/no-unique.js +1 -3
  46. package/src/rules/no-visibility.js +1 -1
  47. package/src/rules/no-wrap.js +1 -1
  48. package/src/rules/variable-pattern.js +4 -4
  49. package/src/utils.js +107 -117
  50. package/Changelog.md +0 -359
package/README.md CHANGED
@@ -38,7 +38,7 @@ Add `no-jquery` to the plugins section of your `.eslintrc` configuration file. Y
38
38
 
39
39
  The config **`plugin:no-jquery/recommended`** includes the recommended rule [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) which is required for method rules to work correctly.
40
40
 
41
- The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.6`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
41
+ The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.7`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
42
42
 
43
43
  The config **`plugin:no-jquery/slim`** includes all features excluded from the official "slim" build of jQuery, specifically the [ajax](https://api.jquery.com/category/ajax/) and [effects](https://api.jquery.com/category/effects/) modules.
44
44
 
@@ -114,7 +114,7 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
114
114
  * [`no-jquery/no-error-shorthand`](docs/rules/no-error-shorthand.md) 🔧 `1.8`
115
115
  * [`no-jquery/no-escape-selector`](docs/rules/no-escape-selector.md) 🔧 `all`
116
116
  * [`no-jquery/no-event-shorthand`](docs/rules/no-event-shorthand.md) ⚙️ 🔧 `3.5`, `3.3†`, `all`
117
- * [`no-jquery/no-extend`](docs/rules/no-extend.md) ⚙️ `all`
117
+ * [`no-jquery/no-extend`](docs/rules/no-extend.md) ⚙️ 🔧 `all`
118
118
  * [`no-jquery/no-fade`](docs/rules/no-fade.md) `slim`, `all`
119
119
  * [`no-jquery/no-filter`](docs/rules/no-filter.md) `all`
120
120
  * [`no-jquery/no-find`](docs/rules/no-find.md)
@@ -37,7 +37,7 @@ Add `no-jquery` to the plugins section of your `.eslintrc` configuration file. Y
37
37
 
38
38
  The config **`plugin:no-jquery/recommended`** includes the recommended rule [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) which is required for method rules to work correctly.
39
39
 
40
- The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.6`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
40
+ The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.7`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
41
41
 
42
42
  The config **`plugin:no-jquery/slim`** includes all features excluded from the official "slim" build of jQuery, specifically the [ajax](https://api.jquery.com/category/ajax/) and [effects](https://api.jquery.com/category/effects/) modules.
43
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-no-jquery",
3
- "version": "2.7.0",
3
+ "version": "3.0.0",
4
4
  "description": "Disallow jQuery functions with native equivalents.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "pretest": "eslint --report-unused-disable-directives .",
18
18
  "test": "nyc mocha --reporter dot tests/** && git diff --exit-code docs/ src/ README.md",
19
- "onlytest": "mocha --reporter dot tests/** --nofix",
19
+ "onlytest": "mocha --reporter dot tests/**",
20
20
  "report": "nyc report --reporter=text-lcov > coverage.lcov",
21
21
  "reporthtml": "nyc report --reporter=html",
22
22
  "testpath": "mocha",
@@ -26,18 +26,21 @@
26
26
  "files": [
27
27
  "src"
28
28
  ],
29
+ "engine": {
30
+ "node": ">=16"
31
+ },
29
32
  "peerDependencies": {
30
- "eslint": ">=2.3.0"
33
+ "eslint": ">=8.0.0"
31
34
  },
32
35
  "devDependencies": {
33
36
  "codecov": "^3.8.3",
34
- "eslint-config-wikimedia": "^0.20.0",
35
- "eslint-docgen": "^0.5.1",
36
- "eslint-plugin-eslint-plugin": "^3.6.1",
37
+ "eslint-config-wikimedia": "^0.28.0",
38
+ "eslint-docgen": "^0.7.1",
39
+ "eslint-plugin-eslint-plugin": "^6.1.0",
37
40
  "eslint-plugin-self": "^1.2.1",
38
- "jquery": "3.6.0",
39
- "jsdom": "^16.7.0",
40
- "mocha": "^8.4.0",
41
+ "jquery": "3.7.1",
42
+ "jsdom": "^22.1.0",
43
+ "mocha": "^10.2.0",
41
44
  "nyc": "^15.1.0"
42
45
  },
43
46
  "bugs": {
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ "overrides": [
3
+ {
4
+ // Rules applying to index.js are used to autofix documentation
5
+ "files": [
6
+ "index.js"
7
+ ],
8
+ "rules": {
9
+ // Allow non-arrow functions in examples
10
+ "prefer-arrow-callback": "off",
11
+ // Allow compact single line functions
12
+ "max-statements-per-line": "off",
13
+ "brace-style": "off"
14
+ }
15
+ }
16
+ ]
17
+ };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- <!-- This file is built by build-all-methods.js; do not edit it directly. -->
3
+ /* This file is built by build-all-methods.js; do not edit it directly. */
4
4
  module.exports = [
5
5
  'add',
6
6
  'addBack',
@@ -135,6 +135,7 @@ module.exports = [
135
135
  'triggerHandler',
136
136
  'unbind',
137
137
  'undelegate',
138
+ 'uniqueSort',
138
139
  'unwrap',
139
140
  'val',
140
141
  'width',
package/src/index.js CHANGED
@@ -126,9 +126,12 @@ module.exports = {
126
126
  },
127
127
  // Use this config if you want to avoid all known deprecated jQuery tools.
128
128
  deprecated: {
129
+ extends: 'plugin:no-jquery/deprecated-3.7'
130
+ },
131
+ // Use this config if you're writing code targetting jQuery 3.7.x environments.
132
+ 'deprecated-3.7': {
129
133
  extends: 'plugin:no-jquery/deprecated-3.6'
130
134
  },
131
- // Use this config if you're writing code targetting jQuery 3.6.x environments.
132
135
  'deprecated-3.6': {
133
136
  extends: 'plugin:no-jquery/deprecated-3.5'
134
137
  },
@@ -20,36 +20,34 @@ module.exports = {
20
20
  schema: []
21
21
  },
22
22
 
23
- create: function ( context ) {
24
- return {
25
- 'CallExpression:exit': function ( node ) {
26
- if ( node.callee.type !== 'MemberExpression' ) {
27
- return;
28
- }
29
- let usedMethod;
30
- if (
31
- node.callee.property.name === 'on' &&
23
+ create: ( context ) => ( {
24
+ 'CallExpression:exit': ( node ) => {
25
+ if ( node.callee.type !== 'MemberExpression' ) {
26
+ return;
27
+ }
28
+ let usedMethod;
29
+ if (
30
+ node.callee.property.name === 'on' &&
32
31
  node.arguments.length >= 1
33
- ) {
34
- const arg = node.arguments[ 0 ];
35
- if (
36
- arg.type === 'Literal' &&
32
+ ) {
33
+ const arg = node.arguments[ 0 ];
34
+ if (
35
+ arg.type === 'Literal' &&
37
36
  disallowedEvents.includes( arg.value )
38
- ) {
39
- usedMethod = arg.value;
40
- }
41
- }
42
- if ( disallowedEvents.includes( node.callee.property.name ) ) {
43
- usedMethod = node.callee.property.name;
44
- }
45
- if ( usedMethod && utils.isjQuery( context, node ) ) {
46
- context.report( {
47
- node: node,
48
- message: 'Prefer local event to {{method}}',
49
- data: { method: usedMethod }
50
- } );
37
+ ) {
38
+ usedMethod = arg.value;
51
39
  }
52
40
  }
53
- };
54
- }
41
+ if ( disallowedEvents.includes( node.callee.property.name ) ) {
42
+ usedMethod = node.callee.property.name;
43
+ }
44
+ if ( usedMethod && utils.isjQuery( context, node ) ) {
45
+ context.report( {
46
+ node,
47
+ message: 'Prefer local event to {{method}}',
48
+ data: { method: usedMethod }
49
+ } );
50
+ }
51
+ }
52
+ } )
55
53
  };
@@ -6,5 +6,5 @@ module.exports = utils.createUtilMethodRule(
6
6
  [ 'ajax', 'get', 'getJSON', 'getScript', 'post' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer `Window.fetch`' :
9
- `Prefer Window.fetch to $.${node.callee.property.name}`
9
+ `Prefer Window.fetch to $.${ node.callee.property.name }`
10
10
  );
@@ -7,8 +7,6 @@ module.exports = utils.createCollectionMethodRule(
7
7
  'Prefer `.addBack` to `.andSelf`',
8
8
  {
9
9
  fixable: 'code',
10
- fix: function ( node, context, fixer ) {
11
- return fixer.replaceText( node.callee.property, 'addBack' );
12
- }
10
+ fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'addBack' )
13
11
  }
14
12
  );
@@ -14,11 +14,11 @@ module.exports = {
14
14
  schema: []
15
15
  },
16
16
 
17
- create: function ( context ) {
17
+ create: ( context ) => {
18
18
  const forbidden = [ 'show', 'hide', 'toggle' ];
19
19
 
20
20
  return {
21
- 'CallExpression:exit': function ( node ) {
21
+ 'CallExpression:exit': ( node ) => {
22
22
  if (
23
23
  node.callee.type !== 'MemberExpression' ||
24
24
  !forbidden.includes( node.callee.property.name ) ||
@@ -45,7 +45,7 @@ module.exports = {
45
45
 
46
46
  if ( utils.isjQuery( context, node ) ) {
47
47
  context.report( {
48
- node: node,
48
+ node,
49
49
  message: 'Prefer CSS transitions to .{{method}}',
50
50
  data: { method: node.callee.property.name }
51
51
  } );
@@ -23,39 +23,37 @@ module.exports = {
23
23
  ]
24
24
  },
25
25
 
26
- create: function ( context ) {
27
- return {
28
- 'CallExpression:exit': function ( node ) {
29
- if (
30
- node.callee.type !== 'MemberExpression' ||
26
+ create: ( context ) => ( {
27
+ 'CallExpression:exit': ( node ) => {
28
+ if (
29
+ node.callee.type !== 'MemberExpression' ||
31
30
  node.callee.property.name !== 'animate'
32
- ) {
33
- return;
34
- }
35
- const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll;
36
- if ( allowScroll ) {
37
- const arg = node.arguments[ 0 ];
38
- // Check properties list has more than just scrollTop/scrollLeft
39
- if ( arg && arg.type === 'ObjectExpression' ) {
40
- if (
41
- arg.properties.every(
42
- ( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft'
43
- )
44
- ) {
45
- return;
46
- }
31
+ ) {
32
+ return;
33
+ }
34
+ const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll;
35
+ if ( allowScroll ) {
36
+ const arg = node.arguments[ 0 ];
37
+ // Check properties list has more than just scrollTop/scrollLeft
38
+ if ( arg && arg.type === 'ObjectExpression' ) {
39
+ if (
40
+ arg.properties.every(
41
+ ( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft'
42
+ )
43
+ ) {
44
+ return;
47
45
  }
48
46
  }
47
+ }
49
48
 
50
- if ( utils.isjQuery( context, node ) ) {
51
- context.report( {
52
- node: node,
53
- message: allowScroll ?
54
- 'Prefer CSS transitions to .animate' :
55
- 'Prefer CSS transitions or CSS scroll-behaviour to .animate'
56
- } );
57
- }
49
+ if ( utils.isjQuery( context, node ) ) {
50
+ context.report( {
51
+ node,
52
+ message: allowScroll ?
53
+ 'Prefer CSS transitions to .animate' :
54
+ 'Prefer CSS transitions or CSS scroll-behaviour to .animate'
55
+ } );
58
56
  }
59
- };
60
- }
57
+ }
58
+ } )
61
59
  };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const utils = require( '../utils.js' );
4
- const methods = [ 'append', 'prepend', 'before', 'after', 'replaceWith' ];
4
+ const methods = [ 'append', 'prepend', 'before', 'after', 'replaceWith', 'add', 'appendTo', 'prependTo' ];
5
5
 
6
6
  function alljQueryOrEmpty( context, node ) {
7
7
  if ( node.type === 'ConditionalExpression' ) {
@@ -28,26 +28,24 @@ module.exports = {
28
28
  schema: []
29
29
  },
30
30
 
31
- create: function ( context ) {
32
- return {
33
- 'CallExpression:exit': function ( node ) {
34
- if ( !(
35
- node.callee.type === 'MemberExpression' &&
31
+ create: ( context ) => ( {
32
+ 'CallExpression:exit': ( node ) => {
33
+ if ( !(
34
+ node.callee.type === 'MemberExpression' &&
36
35
  methods.includes( node.callee.property.name )
37
- ) ) {
38
- return;
39
- }
40
- if ( node.arguments.every( ( arg ) => alljQueryOrEmpty( context, arg ) ) ) {
41
- return;
42
- }
36
+ ) ) {
37
+ return;
38
+ }
39
+ if ( node.arguments.every( ( arg ) => alljQueryOrEmpty( context, arg ) ) ) {
40
+ return;
41
+ }
43
42
 
44
- if ( utils.isjQuery( context, node.callee ) ) {
45
- context.report( {
46
- node: node,
47
- message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.'
48
- } );
49
- }
43
+ if ( utils.isjQuery( context, node.callee ) ) {
44
+ context.report( {
45
+ node,
46
+ message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.'
47
+ } );
50
48
  }
51
- };
52
- }
49
+ }
50
+ } )
53
51
  };
@@ -15,12 +15,11 @@ module.exports = {
15
15
  schema: []
16
16
  },
17
17
 
18
- create: function ( context ) {
19
- return {
20
- 'CallExpression:exit': function ( node ) {
21
- if ( !(
22
- node.callee.type === 'MemberExpression' && (
23
- node.callee.property.name === 'hasClass' ||
18
+ create: ( context ) => ( {
19
+ 'CallExpression:exit': ( node ) => {
20
+ if ( !(
21
+ node.callee.type === 'MemberExpression' && (
22
+ node.callee.property.name === 'hasClass' ||
24
23
  // toggleClass with one argument will check if the
25
24
  // class is already in the DOM before deciding what to do,
26
25
  // so it is equivalent to using hasClass.
@@ -28,18 +27,17 @@ module.exports = {
28
27
  node.callee.property.name === 'toggleClass' &&
29
28
  node.arguments.length === 1
30
29
  )
31
- )
32
- ) ) {
33
- return;
34
- }
30
+ )
31
+ ) ) {
32
+ return;
33
+ }
35
34
 
36
- if ( utils.isjQuery( context, node.callee ) ) {
37
- context.report( {
38
- node: node,
39
- message: 'Where possible, maintain application state in JS to avoid slower DOM queries'
40
- } );
41
- }
35
+ if ( utils.isjQuery( context, node.callee ) ) {
36
+ context.report( {
37
+ node,
38
+ message: 'Where possible, maintain application state in JS to avoid slower DOM queries'
39
+ } );
42
40
  }
43
- };
44
- }
41
+ }
42
+ } )
45
43
  };
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionMethodRule(
6
6
  [ 'addClass', 'hasClass', 'removeClass', 'toggleClass' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer `Element#classList`' :
9
- `Prefer Element#classList to .${node.callee.property.name}`
9
+ `Prefer Element#classList to .${ node.callee.property.name }`
10
10
  );
@@ -11,35 +11,33 @@ module.exports = {
11
11
  schema: []
12
12
  },
13
13
 
14
- create: function ( context ) {
15
- return {
16
- 'CallExpression:exit': function ( node ) {
17
- if ( node.callee.type === 'MemberExpression' ) {
18
- if ( !(
19
- node.callee.property.name === 'add' &&
14
+ create: ( context ) => ( {
15
+ 'CallExpression:exit': ( node ) => {
16
+ if ( node.callee.type === 'MemberExpression' ) {
17
+ if ( !(
18
+ node.callee.property.name === 'add' &&
20
19
  utils.isjQuery( context, node.callee ) &&
21
20
  node.arguments[ 1 ] &&
22
21
  node.arguments[ 1 ].type === 'ObjectExpression'
23
- ) ) {
24
- return;
25
- }
26
- } else if ( node.callee.type === 'Identifier' ) {
27
- if ( !(
28
- utils.isjQueryConstructor( context, node.callee.name ) &&
22
+ ) ) {
23
+ return;
24
+ }
25
+ } else if ( node.callee.type === 'Identifier' ) {
26
+ if ( !(
27
+ utils.isjQueryConstructor( context, node.callee.name ) &&
29
28
  node.arguments[ 1 ] &&
30
29
  node.arguments[ 1 ].type === 'ObjectExpression'
31
- ) ) {
32
- return;
33
- }
34
- } else {
30
+ ) ) {
35
31
  return;
36
32
  }
37
-
38
- context.report( {
39
- node: node,
40
- message: 'Prefer .attr to constructor attributes'
41
- } );
33
+ } else {
34
+ return;
42
35
  }
43
- };
44
- }
36
+
37
+ context.report( {
38
+ node,
39
+ message: 'Prefer .attr to constructor attributes'
40
+ } );
41
+ }
42
+ } )
45
43
  };
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionOrUtilMethodRule(
6
6
  [ 'data', 'removeData', 'hasData' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer `WeakMap`' :
9
- `Prefer WeakMap to .${node.callee.property.name}/$.${node.callee.property.name}`
9
+ `Prefer WeakMap to .${ node.callee.property.name }/$.${ node.callee.property.name }`
10
10
  );
@@ -11,7 +11,7 @@ module.exports = {
11
11
  schema: []
12
12
  },
13
13
 
14
- create: function ( context ) {
14
+ create: ( context ) => {
15
15
  function enforce( node ) {
16
16
  if (
17
17
  node.callee.type !== 'MemberExpression' ||
@@ -22,7 +22,7 @@ module.exports = {
22
22
  }
23
23
 
24
24
  context.report( {
25
- node: node,
25
+ node,
26
26
  message: 'Prefer Promise to $.Deferred'
27
27
  } );
28
28
  }
@@ -7,8 +7,6 @@ module.exports = utils.createUtilMethodRule(
7
7
  'Prefer `throw` to `$.error`',
8
8
  {
9
9
  fixable: 'code',
10
- fix: function ( node, context, fixer ) {
11
- return fixer.replaceText( node.callee, 'throw new Error' );
12
- }
10
+ fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'throw new Error' )
13
11
  }
14
12
  );
@@ -7,8 +7,6 @@ module.exports = utils.createUtilMethodRule(
7
7
  'Prefer `CSS.escape` to `$.escapeSelector`',
8
8
  {
9
9
  fixable: 'code',
10
- fix: function ( node, context, fixer ) {
11
- return fixer.replaceText( node.callee, 'CSS.escape' );
12
- }
10
+ fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'CSS.escape' )
13
11
  }
14
12
  );
@@ -48,7 +48,7 @@ const rule = utils.createCollectionMethodRule(
48
48
  ].concat( ajaxEvents ),
49
49
  ( node ) => node === true ?
50
50
  'Use the `allowAjaxEvents` option to allow `ajax*` methods. Prefer `.on` or `.trigger`' :
51
- `Prefer .on or .trigger to .${node.callee.property.name}`,
51
+ `Prefer .on or .trigger to .${ node.callee.property.name }`,
52
52
  {
53
53
  fixable: 'code',
54
54
  fix: utils.eventShorthandFixer
@@ -69,10 +69,10 @@ rule.meta.schema = [
69
69
 
70
70
  const parentCreate = rule.create;
71
71
 
72
- rule.create = function ( context ) {
72
+ rule.create = ( context ) => {
73
73
  const rules = parentCreate( context );
74
74
  return {
75
- 'CallExpression:exit': function ( node ) {
75
+ 'CallExpression:exit': ( node ) => {
76
76
  if (
77
77
  node.callee.type === 'MemberExpression' &&
78
78
  context.options[ 0 ] && context.options[ 0 ].allowAjaxEvents
@@ -8,6 +8,7 @@ module.exports = {
8
8
  docs: {
9
9
  description: 'Disallows the ' + utils.jQueryGlobalLink( 'extend' ) + ' utility. Prefer `Object.assign` or the spread operator.'
10
10
  },
11
+ fixable: 'code',
11
12
  schema: [
12
13
  {
13
14
  type: 'object',
@@ -21,32 +22,33 @@ module.exports = {
21
22
  ]
22
23
  },
23
24
 
24
- create: function ( context ) {
25
- return {
26
- 'CallExpression:exit': function ( node ) {
27
- if ( node.callee.type !== 'MemberExpression' ) {
28
- return;
29
- }
30
- const name = node.callee.property.name;
31
- if (
32
- name !== 'extend' ||
25
+ create: ( context ) => ( {
26
+ 'CallExpression:exit': ( node ) => {
27
+ if ( node.callee.type !== 'MemberExpression' ) {
28
+ return;
29
+ }
30
+ const name = node.callee.property.name;
31
+ if (
32
+ name !== 'extend' ||
33
33
  !utils.isjQueryConstructor( context, node.callee.object.name )
34
- ) {
35
- return;
36
- }
37
- const allowDeep = context.options[ 0 ] && context.options[ 0 ].allowDeep;
38
- if (
39
- allowDeep &&
40
- node.arguments[ 0 ] && node.arguments[ 0 ].value === true
41
- ) {
42
- return;
43
- }
44
-
45
- context.report( {
46
- node: node,
47
- message: 'Prefer Object.assign or the spread operator to $.extend'
48
- } );
34
+ ) {
35
+ return;
49
36
  }
50
- };
51
- }
37
+ const allowDeep = context.options[ 0 ] && context.options[ 0 ].allowDeep;
38
+ const isDeep = node.arguments[ 0 ] && node.arguments[ 0 ].value === true;
39
+ if ( allowDeep && isDeep ) {
40
+ return;
41
+ }
42
+
43
+ context.report( {
44
+ node,
45
+ message: 'Prefer Object.assign or the spread operator to $.extend',
46
+ fix: function ( fixer ) {
47
+ if ( !isDeep ) {
48
+ return fixer.replaceText( node.callee, 'Object.assign' );
49
+ }
50
+ }
51
+ } );
52
+ }
53
+ } )
52
54
  };
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionMethodRule(
6
6
  [ 'fadeIn', 'fadeOut', 'fadeTo', 'fadeToggle' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer CSS transitions' :
9
- `Prefer CSS transitions to .${node.callee.property.name}`
9
+ `Prefer CSS transitions to .${ node.callee.property.name }`
10
10
  );
@@ -11,23 +11,21 @@ module.exports = {
11
11
  schema: []
12
12
  },
13
13
 
14
- create: function ( context ) {
15
- return {
16
- MemberExpression: function ( node ) {
17
- if (
18
- !utils.isjQueryConstructor( context, node.object.name ) ||
14
+ create: ( context ) => ( {
15
+ MemberExpression: ( node ) => {
16
+ if (
17
+ !utils.isjQueryConstructor( context, node.object.name ) ||
19
18
  node.property.name !== 'fx' ||
20
19
  !node.parent.property ||
21
20
  node.parent.property.name !== 'interval'
22
- ) {
23
- return;
24
- }
25
-
26
- context.report( {
27
- node: node,
28
- message: '$.fx.interval is not allowed'
29
- } );
21
+ ) {
22
+ return;
30
23
  }
31
- };
32
- }
24
+
25
+ context.report( {
26
+ node,
27
+ message: '$.fx.interval is not allowed'
28
+ } );
29
+ }
30
+ } )
33
31
  };