eslint-plugin-no-jquery
Advanced tools
| module.exports = { | ||
| "overrides": [ | ||
| { | ||
| // Rules applying to index.js are used to autofix documentation | ||
| "files": [ | ||
| "index.js" | ||
| ], | ||
| "rules": { | ||
| // Allow non-arrow functions in examples | ||
| "prefer-arrow-callback": "off", | ||
| // Allow compact single line functions | ||
| "max-statements-per-line": "off", | ||
| "brace-style": "off" | ||
| } | ||
| } | ||
| ] | ||
| }; |
+12
-9
| { | ||
| "name": "eslint-plugin-no-jquery", | ||
| "version": "2.7.0", | ||
| "version": "3.0.0", | ||
| "description": "Disallow jQuery functions with native equivalents.", | ||
@@ -19,3 +19,3 @@ "repository": { | ||
| "test": "nyc mocha --reporter dot tests/** && git diff --exit-code docs/ src/ README.md", | ||
| "onlytest": "mocha --reporter dot tests/** --nofix", | ||
| "onlytest": "mocha --reporter dot tests/**", | ||
| "report": "nyc report --reporter=text-lcov > coverage.lcov", | ||
@@ -30,14 +30,17 @@ "reporthtml": "nyc report --reporter=html", | ||
| ], | ||
| "engine": { | ||
| "node": ">=16" | ||
| }, | ||
| "peerDependencies": { | ||
| "eslint": ">=2.3.0" | ||
| "eslint": ">=8.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "codecov": "^3.8.3", | ||
| "eslint-config-wikimedia": "^0.20.0", | ||
| "eslint-docgen": "^0.5.1", | ||
| "eslint-plugin-eslint-plugin": "^3.6.1", | ||
| "eslint-config-wikimedia": "^0.28.0", | ||
| "eslint-docgen": "^0.7.1", | ||
| "eslint-plugin-eslint-plugin": "^6.1.0", | ||
| "eslint-plugin-self": "^1.2.1", | ||
| "jquery": "3.6.0", | ||
| "jsdom": "^16.7.0", | ||
| "mocha": "^8.4.0", | ||
| "jquery": "3.7.1", | ||
| "jsdom": "^22.1.0", | ||
| "mocha": "^10.2.0", | ||
| "nyc": "^15.1.0" | ||
@@ -44,0 +47,0 @@ }, |
+2
-2
@@ -41,3 +41,3 @@ <!-- This file is built by build-readme.js. Do not edit it directly; edit README.md.template instead. --> | ||
| 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. | ||
| 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. | ||
@@ -118,3 +118,3 @@ 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. | ||
| * [`no-jquery/no-event-shorthand`](docs/rules/no-event-shorthand.md) ⚙️ 🔧 `3.5`, `3.3†`, `all` | ||
| * [`no-jquery/no-extend`](docs/rules/no-extend.md) ⚙️ `all` | ||
| * [`no-jquery/no-extend`](docs/rules/no-extend.md) ⚙️ 🔧 `all` | ||
| * [`no-jquery/no-fade`](docs/rules/no-fade.md) `slim`, `all` | ||
@@ -121,0 +121,0 @@ * [`no-jquery/no-filter`](docs/rules/no-filter.md) `all` |
| 'use strict'; | ||
| <!-- This file is built by build-all-methods.js; do not edit it directly. --> | ||
| /* This file is built by build-all-methods.js; do not edit it directly. */ | ||
| module.exports = [ | ||
@@ -138,2 +138,3 @@ 'add', | ||
| 'undelegate', | ||
| 'uniqueSort', | ||
| 'unwrap', | ||
@@ -140,0 +141,0 @@ 'val', |
+4
-1
@@ -129,5 +129,8 @@ 'use strict'; | ||
| deprecated: { | ||
| extends: 'plugin:no-jquery/deprecated-3.7' | ||
| }, | ||
| // Use this config if you're writing code targetting jQuery 3.7.x environments. | ||
| 'deprecated-3.7': { | ||
| extends: 'plugin:no-jquery/deprecated-3.6' | ||
| }, | ||
| // Use this config if you're writing code targetting jQuery 3.6.x environments. | ||
| 'deprecated-3.6': { | ||
@@ -134,0 +137,0 @@ extends: 'plugin:no-jquery/deprecated-3.5' |
@@ -23,34 +23,32 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| let usedMethod; | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| let usedMethod; | ||
| if ( | ||
| node.callee.property.name === 'on' && | ||
| node.arguments.length >= 1 | ||
| ) { | ||
| const arg = node.arguments[ 0 ]; | ||
| if ( | ||
| node.callee.property.name === 'on' && | ||
| node.arguments.length >= 1 | ||
| arg.type === 'Literal' && | ||
| disallowedEvents.includes( arg.value ) | ||
| ) { | ||
| const arg = node.arguments[ 0 ]; | ||
| if ( | ||
| arg.type === 'Literal' && | ||
| disallowedEvents.includes( arg.value ) | ||
| ) { | ||
| usedMethod = arg.value; | ||
| } | ||
| usedMethod = arg.value; | ||
| } | ||
| if ( disallowedEvents.includes( node.callee.property.name ) ) { | ||
| usedMethod = node.callee.property.name; | ||
| } | ||
| if ( usedMethod && utils.isjQuery( context, node ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: 'Prefer local event to {{method}}', | ||
| data: { method: usedMethod } | ||
| } ); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| if ( disallowedEvents.includes( node.callee.property.name ) ) { | ||
| usedMethod = node.callee.property.name; | ||
| } | ||
| if ( usedMethod && utils.isjQuery( context, node ) ) { | ||
| context.report( { | ||
| node, | ||
| message: 'Prefer local event to {{method}}', | ||
| data: { method: usedMethod } | ||
| } ); | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer `Window.fetch`' : | ||
| `Prefer Window.fetch to $.${node.callee.property.name}` | ||
| `Prefer Window.fetch to $.${ node.callee.property.name }` | ||
| ); |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee.property, 'addBack' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'addBack' ) | ||
| } | ||
| ); |
@@ -17,7 +17,7 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| create: ( context ) => { | ||
| const forbidden = [ 'show', 'hide', 'toggle' ]; | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
@@ -49,3 +49,3 @@ node.callee.type !== 'MemberExpression' || | ||
| context.report( { | ||
| node: node, | ||
| node, | ||
| message: 'Prefer CSS transitions to .{{method}}', | ||
@@ -52,0 +52,0 @@ data: { method: node.callee.property.name } |
+28
-30
@@ -26,37 +26,35 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( | ||
| node.callee.type !== 'MemberExpression' || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
| node.callee.type !== 'MemberExpression' || | ||
| node.callee.property.name !== 'animate' | ||
| ) { | ||
| return; | ||
| } | ||
| const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll; | ||
| if ( allowScroll ) { | ||
| const arg = node.arguments[ 0 ]; | ||
| // Check properties list has more than just scrollTop/scrollLeft | ||
| if ( arg && arg.type === 'ObjectExpression' ) { | ||
| if ( | ||
| arg.properties.every( | ||
| ( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft' | ||
| ) | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll; | ||
| if ( allowScroll ) { | ||
| const arg = node.arguments[ 0 ]; | ||
| // Check properties list has more than just scrollTop/scrollLeft | ||
| if ( arg && arg.type === 'ObjectExpression' ) { | ||
| if ( | ||
| arg.properties.every( | ||
| ( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft' | ||
| ) | ||
| ) { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| if ( utils.isjQuery( context, node ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: allowScroll ? | ||
| 'Prefer CSS transitions to .animate' : | ||
| 'Prefer CSS transitions or CSS scroll-behaviour to .animate' | ||
| } ); | ||
| } | ||
| if ( utils.isjQuery( context, node ) ) { | ||
| context.report( { | ||
| node, | ||
| message: allowScroll ? | ||
| 'Prefer CSS transitions to .animate' : | ||
| 'Prefer CSS transitions or CSS scroll-behaviour to .animate' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } ) | ||
| }; |
| 'use strict'; | ||
| const utils = require( '../utils.js' ); | ||
| const methods = [ 'append', 'prepend', 'before', 'after', 'replaceWith' ]; | ||
| const methods = [ 'append', 'prepend', 'before', 'after', 'replaceWith', 'add', 'appendTo', 'prependTo' ]; | ||
@@ -31,24 +31,22 @@ function alljQueryOrEmpty( context, node ) { | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( !( | ||
| node.callee.type === 'MemberExpression' && | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( !( | ||
| node.callee.type === 'MemberExpression' && | ||
| methods.includes( node.callee.property.name ) | ||
| ) ) { | ||
| return; | ||
| } | ||
| if ( node.arguments.every( ( arg ) => alljQueryOrEmpty( context, arg ) ) ) { | ||
| return; | ||
| } | ||
| ) ) { | ||
| return; | ||
| } | ||
| if ( node.arguments.every( ( arg ) => alljQueryOrEmpty( context, arg ) ) ) { | ||
| return; | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.' | ||
| } ); | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -18,8 +18,7 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( !( | ||
| node.callee.type === 'MemberExpression' && ( | ||
| node.callee.property.name === 'hasClass' || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( !( | ||
| node.callee.type === 'MemberExpression' && ( | ||
| node.callee.property.name === 'hasClass' || | ||
| // toggleClass with one argument will check if the | ||
@@ -32,16 +31,15 @@ // class is already in the DOM before deciding what to do, | ||
| ) | ||
| ) | ||
| ) ) { | ||
| return; | ||
| } | ||
| ) | ||
| ) ) { | ||
| return; | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: 'Where possible, maintain application state in JS to avoid slower DOM queries' | ||
| } ); | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: 'Where possible, maintain application state in JS to avoid slower DOM queries' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer `Element#classList`' : | ||
| `Prefer Element#classList to .${node.callee.property.name}` | ||
| `Prefer Element#classList to .${ node.callee.property.name }` | ||
| ); |
@@ -14,33 +14,31 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type === 'MemberExpression' ) { | ||
| if ( !( | ||
| node.callee.property.name === 'add' && | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type === 'MemberExpression' ) { | ||
| if ( !( | ||
| node.callee.property.name === 'add' && | ||
| utils.isjQuery( context, node.callee ) && | ||
| node.arguments[ 1 ] && | ||
| node.arguments[ 1 ].type === 'ObjectExpression' | ||
| ) ) { | ||
| return; | ||
| } | ||
| } else if ( node.callee.type === 'Identifier' ) { | ||
| if ( !( | ||
| utils.isjQueryConstructor( context, node.callee.name ) && | ||
| ) ) { | ||
| return; | ||
| } | ||
| } else if ( node.callee.type === 'Identifier' ) { | ||
| if ( !( | ||
| utils.isjQueryConstructor( context, node.callee.name ) && | ||
| node.arguments[ 1 ] && | ||
| node.arguments[ 1 ].type === 'ObjectExpression' | ||
| ) ) { | ||
| return; | ||
| } | ||
| } else { | ||
| ) ) { | ||
| return; | ||
| } | ||
| } else { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: 'Prefer .attr to constructor attributes' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message: 'Prefer .attr to constructor attributes' | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer `WeakMap`' : | ||
| `Prefer WeakMap to .${node.callee.property.name}/$.${node.callee.property.name}` | ||
| `Prefer WeakMap to .${ node.callee.property.name }/$.${ node.callee.property.name }` | ||
| ); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| create: ( context ) => { | ||
| function enforce( node ) { | ||
@@ -26,3 +26,3 @@ if ( | ||
| context.report( { | ||
| node: node, | ||
| node, | ||
| message: 'Prefer Promise to $.Deferred' | ||
@@ -29,0 +29,0 @@ } ); |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee, 'throw new Error' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'throw new Error' ) | ||
| } | ||
| ); |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee, 'CSS.escape' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'CSS.escape' ) | ||
| } | ||
| ); |
@@ -51,3 +51,3 @@ 'use strict'; | ||
| 'Use the `allowAjaxEvents` option to allow `ajax*` methods. Prefer `.on` or `.trigger`' : | ||
| `Prefer .on or .trigger to .${node.callee.property.name}`, | ||
| `Prefer .on or .trigger to .${ node.callee.property.name }`, | ||
| { | ||
@@ -73,6 +73,6 @@ fixable: 'code', | ||
| rule.create = function ( context ) { | ||
| rule.create = ( context ) => { | ||
| const rules = parentCreate( context ); | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
@@ -79,0 +79,0 @@ node.callee.type === 'MemberExpression' && |
+28
-26
@@ -11,2 +11,3 @@ 'use strict'; | ||
| }, | ||
| fixable: 'code', | ||
| schema: [ | ||
@@ -25,30 +26,31 @@ { | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| name !== 'extend' || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| name !== 'extend' || | ||
| !utils.isjQueryConstructor( context, node.callee.object.name ) | ||
| ) { | ||
| return; | ||
| ) { | ||
| return; | ||
| } | ||
| const allowDeep = context.options[ 0 ] && context.options[ 0 ].allowDeep; | ||
| const isDeep = node.arguments[ 0 ] && node.arguments[ 0 ].value === true; | ||
| if ( allowDeep && isDeep ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message: 'Prefer Object.assign or the spread operator to $.extend', | ||
| fix: function ( fixer ) { | ||
| if ( !isDeep ) { | ||
| return fixer.replaceText( node.callee, 'Object.assign' ); | ||
| } | ||
| } | ||
| const allowDeep = context.options[ 0 ] && context.options[ 0 ].allowDeep; | ||
| if ( | ||
| allowDeep && | ||
| node.arguments[ 0 ] && node.arguments[ 0 ].value === true | ||
| ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: 'Prefer Object.assign or the spread operator to $.extend' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer CSS transitions' : | ||
| `Prefer CSS transitions to .${node.callee.property.name}` | ||
| `Prefer CSS transitions to .${ node.callee.property.name }` | ||
| ); |
@@ -14,21 +14,19 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| MemberExpression: function ( node ) { | ||
| if ( | ||
| !utils.isjQueryConstructor( context, node.object.name ) || | ||
| create: ( context ) => ( { | ||
| MemberExpression: ( node ) => { | ||
| if ( | ||
| !utils.isjQueryConstructor( context, node.object.name ) || | ||
| node.property.name !== 'fx' || | ||
| !node.parent.property || | ||
| node.parent.property.name !== 'interval' | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: '$.fx.interval is not allowed' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message: '$.fx.interval is not allowed' | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -31,40 +31,39 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( | ||
| node.callee.type !== 'Identifier' || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
| node.callee.type !== 'Identifier' || | ||
| !utils.isjQueryConstructor( context, node.callee.name ) || | ||
| !node.arguments[ 0 ] || | ||
| node.arguments[ 0 ].type !== 'Literal' | ||
| ) { | ||
| return; | ||
| } | ||
| const value = node.arguments[ 0 ].value; | ||
| const allowIds = context.options[ 0 ] && context.options[ 0 ].allowIds; | ||
| if ( | ||
| typeof value !== 'string' || | ||
| ) { | ||
| return; | ||
| } | ||
| const value = node.arguments[ 0 ].value; | ||
| const allowIds = context.options[ 0 ] && context.options[ 0 ].allowIds; | ||
| if ( | ||
| typeof value !== 'string' || | ||
| !value || | ||
| value === '#' || | ||
| ( allowIds && idPattern.test( value.trim() ) ) | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| // Simple HTML check (copied from jQuery) | ||
| if ( | ||
| value[ 0 ] === '<' && | ||
| // Simple HTML check (copied from jQuery) | ||
| if ( | ||
| value[ 0 ] === '<' && | ||
| value[ value.length - 1 ] === '>' && | ||
| value.length >= 3 | ||
| ) { | ||
| return; | ||
| } | ||
| if ( rquickExpr.exec( value ) ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| if ( rquickExpr.exec( value ) ) { | ||
| return; | ||
| } | ||
| const selectorContext = node.arguments[ 1 ]; | ||
| if ( selectorContext ) { | ||
| if ( | ||
| selectorContext.type !== 'Literal' && | ||
| const selectorContext = node.arguments[ 1 ]; | ||
| if ( selectorContext ) { | ||
| if ( | ||
| selectorContext.type !== 'Literal' && | ||
| !( | ||
@@ -74,17 +73,16 @@ selectorContext.type === 'Identifier' && | ||
| ) | ||
| ) { | ||
| return; | ||
| } | ||
| if ( selectorContext.value === '#' ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| if ( selectorContext.value === '#' ) { | ||
| return; | ||
| } | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: 'Avoid queries which search the entire DOM. Keep DOM nodes in memory where possible.' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message: 'Avoid queries which search the entire DOM. Keep DOM nodes in memory where possible.' | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee, 'Array.isArray' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'Array.isArray' ) | ||
| } | ||
| ); |
@@ -10,3 +10,3 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| fix: ( node, context, fixer ) => { | ||
| const calleeRange = node.callee.range; | ||
@@ -13,0 +13,0 @@ return [ |
@@ -14,19 +14,17 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( | ||
| node.callee.type !== 'Identifier' || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
| node.callee.type !== 'Identifier' || | ||
| !utils.isjQueryConstructor( context, node.callee.name ) | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: 'The jQuery constructor is not allowed' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message: 'The jQuery constructor is not allowed' | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -15,26 +15,24 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( !( | ||
| node.callee.type === 'MemberExpression' && | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( !( | ||
| node.callee.type === 'MemberExpression' && | ||
| !utils.isjQueryConstructor( context, node.callee.object.name ) && | ||
| node.callee.property.name === 'load' && ( | ||
| node.arguments.length === 0 || | ||
| node.arguments.length === 0 || | ||
| utils.isFunction( node.arguments[ 0 ] ) | ||
| ) | ||
| ) ) { | ||
| return; | ||
| } | ||
| ) | ||
| ) ) { | ||
| return; | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: 'Prefer .on or .trigger to .load', | ||
| fix: utils.eventShorthandFixer.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: 'Prefer .on or .trigger to .load', | ||
| fix: utils.eventShorthandFixer.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node, '(function(){})' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node, '(function(){})' ) | ||
| } | ||
| ); |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee, 'Date.now' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'Date.now' ) | ||
| } | ||
| ); |
+29
-34
@@ -15,39 +15,34 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( | ||
| node.callee.type !== 'MemberExpression' || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
| node.callee.type !== 'MemberExpression' || | ||
| node.callee.property.name !== 'on' | ||
| ) { | ||
| return; | ||
| } | ||
| const arg = node.arguments[ 0 ]; | ||
| if ( !arg || arg.value !== 'ready' ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| const arg = node.arguments[ 0 ]; | ||
| if ( !arg || arg.value !== 'ready' ) { | ||
| return; | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: '.on("ready") is not allowed', | ||
| fix: function ( fixer ) { | ||
| if ( node.arguments.length > 1 ) { | ||
| return [ | ||
| fixer.replaceText( node.callee.property, 'ready' ), | ||
| fixer.replaceTextRange( | ||
| [ | ||
| node.arguments[ 0 ].range[ 0 ], | ||
| node.arguments[ 1 ].range[ 0 ] | ||
| ], | ||
| '' | ||
| ) | ||
| ]; | ||
| } | ||
| } | ||
| } ); | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: '.on("ready") is not allowed', | ||
| fix: ( fixer ) => ( node.arguments.length > 1 ) ? | ||
| [ | ||
| fixer.replaceText( node.callee.property, 'ready' ), | ||
| fixer.replaceTextRange( | ||
| [ | ||
| node.arguments[ 0 ].range[ 0 ], | ||
| node.arguments[ 1 ].range[ 0 ] | ||
| ], | ||
| '' | ||
| ) | ||
| ] : null | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -97,26 +97,24 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !name || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !name || | ||
| methodsWithRules.includes( name ) || | ||
| utils.isjQueryConstructor( context, node.callee.object.name ) | ||
| ) { | ||
| return; | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: '.{{name}} is not allowed', | ||
| data: { name: name } | ||
| } ); | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| }; | ||
| } | ||
| if ( utils.isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: '.{{name}} is not allowed', | ||
| data: { name } | ||
| } ); | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -65,25 +65,23 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !name || | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !name || | ||
| utilsWithRules.includes( name ) || | ||
| !utils.isjQueryConstructor( context, node.callee.object.name ) | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: '$.{{name}} is not allowed', | ||
| data: { name: name } | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message: '$.{{name}} is not allowed', | ||
| data: { name } | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -59,11 +59,10 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| let allowSingle, | ||
| message = 'Prefer DOM building to parsing HTML literals'; | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| let allowSingle, | ||
| message = 'Prefer DOM building to parsing HTML literals'; | ||
| if ( node.callee.type === 'Identifier' ) { | ||
| if ( !( | ||
| utils.isjQueryConstructor( context, node.callee.name ) && | ||
| if ( node.callee.type === 'Identifier' ) { | ||
| if ( !( | ||
| utils.isjQueryConstructor( context, node.callee.name ) && | ||
| node.arguments[ 0 ] && | ||
@@ -74,73 +73,67 @@ ( | ||
| ) | ||
| ) ) { | ||
| return; | ||
| } | ||
| allowSingle = true; | ||
| } else if ( node.callee.type === 'MemberExpression' ) { | ||
| if ( | ||
| utils.isjQueryConstructor( context, node.callee.object.name ) && | ||
| ) ) { | ||
| return; | ||
| } | ||
| allowSingle = true; | ||
| } else if ( node.callee.type === 'MemberExpression' ) { | ||
| if ( | ||
| utils.isjQueryConstructor( context, node.callee.object.name ) && | ||
| node.callee.property.name === 'parseHTML' | ||
| ) { | ||
| allowSingle = false; | ||
| } else if ( | ||
| [ 'html', 'append', 'add' ].includes( node.callee.property.name ) && | ||
| ) { | ||
| allowSingle = false; | ||
| } else if ( | ||
| [ 'html', 'append', 'add' ].includes( node.callee.property.name ) && | ||
| utils.isjQuery( context, node ) | ||
| ) { | ||
| allowSingle = true; | ||
| } else { | ||
| return; | ||
| } | ||
| ) { | ||
| allowSingle = true; | ||
| } else { | ||
| return; | ||
| } | ||
| } else { | ||
| return; | ||
| } | ||
| let expectedTag; | ||
| const arg = node.arguments[ 0 ]; | ||
| if ( allowSingle ) { | ||
| const value = arg && allLiteral( arg ) && joinLiterals( arg ); | ||
| if ( !( typeof value === 'string' && value ) || !rquickExpr.exec( value ) ) { | ||
| // Empty or non-string, or non-HTML | ||
| return; | ||
| } | ||
| let match; | ||
| if ( ( match = rsingleTag.exec( value ) ) ) { | ||
| // Single tag | ||
| const singleTagStyle = ( context.options[ 0 ] && context.options[ 0 ].singleTagStyle ) || 'minimal'; | ||
| if ( singleTagStyle === 'minimal' ) { | ||
| if ( !rsingleTagMinimal.exec( value ) ) { | ||
| expectedTag = '<' + match[ 1 ] + '>'; | ||
| message = 'Single tag must use the format: ' + expectedTag; | ||
| } else { | ||
| return; | ||
| } | ||
| } else if ( singleTagStyle === 'self-closing' ) { | ||
| if ( !rsingleTagSelfClosing.exec( value ) ) { | ||
| expectedTag = '<' + match[ 1 ] + '/>'; | ||
| message = 'Single tag must use the format: ' + expectedTag; | ||
| } else { | ||
| return; | ||
| } | ||
| let expectedTag; | ||
| const arg = node.arguments[ 0 ]; | ||
| if ( allowSingle ) { | ||
| const value = arg && allLiteral( arg ) && joinLiterals( arg ); | ||
| if ( !( typeof value === 'string' && value ) || !rquickExpr.exec( value ) ) { | ||
| // Empty or non-string, or non-HTML | ||
| return; | ||
| } | ||
| let match; | ||
| if ( ( match = rsingleTag.exec( value ) ) ) { | ||
| // Single tag | ||
| const singleTagStyle = ( context.options[ 0 ] && context.options[ 0 ].singleTagStyle ) || 'minimal'; | ||
| if ( singleTagStyle === 'minimal' ) { | ||
| if ( !rsingleTagMinimal.exec( value ) ) { | ||
| expectedTag = '<' + match[ 1 ] + '>'; | ||
| message = 'Single tag must use the format: ' + expectedTag; | ||
| } else { | ||
| // singleTagStyle === 'any' | ||
| return; | ||
| } | ||
| } else if ( singleTagStyle === 'self-closing' ) { | ||
| if ( !rsingleTagSelfClosing.exec( value ) ) { | ||
| expectedTag = '<' + match[ 1 ] + '/>'; | ||
| message = 'Single tag must use the format: ' + expectedTag; | ||
| } else { | ||
| return; | ||
| } | ||
| } else { | ||
| // singleTagStyle === 'any' | ||
| return; | ||
| } | ||
| } else if ( !( arg && allLiteral( arg ) ) ) { | ||
| // Non literals passed to $.parseHTML | ||
| return; | ||
| } | ||
| } else if ( !( arg && allLiteral( arg ) ) ) { | ||
| // Non literals passed to $.parseHTML | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: message, | ||
| fix: function ( fixer ) { | ||
| if ( expectedTag ) { | ||
| return fixer.replaceText( arg, '"' + expectedTag + '"' ); | ||
| } | ||
| return null; | ||
| } | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| context.report( { | ||
| node, | ||
| message, | ||
| fix: ( fixer ) => expectedTag ? fixer.replaceText( arg, '"' + expectedTag + '"' ) : null | ||
| } ); | ||
| } | ||
| } ) | ||
| }; |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee, 'JSON.parse' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'JSON.parse' ) | ||
| } | ||
| ); |
@@ -10,3 +10,3 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| fix: ( node, context, fixer ) => { | ||
| if ( node.arguments.length ) { | ||
@@ -13,0 +13,0 @@ return [ |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer direct property access' : | ||
| `Prefer direct property access to .${node.callee.property.name}/$.${node.callee.property.name}` | ||
| `Prefer direct property access to .${ node.callee.property.name }/$.${ node.callee.property.name }` | ||
| ); |
@@ -10,3 +10,3 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| fix: ( node, context, fixer ) => { | ||
| if ( | ||
@@ -13,0 +13,0 @@ node.arguments.length >= 2 && |
@@ -10,3 +10,3 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| fix: ( node, context, fixer ) => { | ||
| if ( node.parent.type === 'ExpressionStatement' ) { | ||
@@ -13,0 +13,0 @@ return fixer.replaceText( node.callee, '$' ); |
@@ -33,14 +33,12 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( isDirect( context, node ) || isChained( context, node ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: '.ready is not allowed' | ||
| } ); | ||
| } | ||
| create: ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( isDirect( context, node ) || isChained( context, node ) ) { | ||
| context.report( { | ||
| node, | ||
| message: '.ready is not allowed' | ||
| } ); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } ) | ||
| }; |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer `FormData` or `URLSearchParams`' : | ||
| `Prefer FormData or URLSearchParams to .${node.callee.property.name}` | ||
| `Prefer FormData or URLSearchParams to .${ node.callee.property.name }` | ||
| ); |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceTextRange( [ node.callee.property.range[ 0 ], node.range[ 1 ] ], 'length' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceTextRange( [ node.callee.property.range[ 0 ], node.range[ 1 ] ], 'length' ) | ||
| } | ||
| ); |
@@ -42,4 +42,4 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| const forbiddenPositional = /:eq|:even|:first([^-]|$)|:gt|:last([^-]|$)|:lt|:nth|:odd/; | ||
| create: ( context ) => { | ||
| const forbiddenPositional = /:eq|:even|:first([^-]|$)|:gt|:last([^-]|$)|:lt|:nth([^-]|$)|:odd/; | ||
| const forbiddenOther = /:animated|:button|:checkbox|:file|:has|:header|:hidden|:image|:input|:parent|:password|:radio|:reset|:selected|:submit|:text|:visible/; | ||
@@ -67,3 +67,3 @@ const traversals = [ | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( | ||
@@ -88,3 +88,3 @@ !node.arguments[ 0 ] || | ||
| context.report( { | ||
| node: node, | ||
| node, | ||
| message: 'Positional selector extensions are not allowed' | ||
@@ -94,3 +94,3 @@ } ); | ||
| context.report( { | ||
| node: node, | ||
| node, | ||
| message: 'Selector extensions are not allowed' | ||
@@ -97,0 +97,0 @@ } ); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
| 'Prefer CSS transitions' : | ||
| `Prefer CSS transitions to .${node.callee.property.name}` | ||
| `Prefer CSS transitions to .${ node.callee.property.name }` | ||
| ); |
@@ -10,6 +10,4 @@ 'use strict'; | ||
| fixable: 'code', | ||
| fix: function ( node, context, fixer ) { | ||
| return fixer.replaceText( node.callee.property, 'uniqueSort' ); | ||
| } | ||
| fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'uniqueSort' ) | ||
| } | ||
| ); |
@@ -8,3 +8,3 @@ 'use strict'; | ||
| ( node ) => node === true ? '' : | ||
| `.${node.callee.property.name} is not allowed` | ||
| `.${ node.callee.property.name } is not allowed` | ||
| ); |
@@ -8,3 +8,3 @@ 'use strict'; | ||
| ( node ) => node === true ? '' : | ||
| `.${node.callee.property.name} is not allowed` | ||
| `.${ node.callee.property.name } is not allowed` | ||
| ); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
| create: function ( context ) { | ||
| create: ( context ) => { | ||
| function test( node, left, right ) { | ||
@@ -26,3 +26,3 @@ if ( | ||
| context.report( { | ||
| node: node, | ||
| node, | ||
| message: 'jQuery collection names must match the variablePattern' | ||
@@ -34,6 +34,6 @@ } ); | ||
| return { | ||
| 'AssignmentExpression:exit': function ( node ) { | ||
| 'AssignmentExpression:exit': ( node ) => { | ||
| test( node, node.left, node.right ); | ||
| }, | ||
| 'VariableDeclarator:exit': function ( node ) { | ||
| 'VariableDeclarator:exit': ( node ) => { | ||
| test( node, node.id, node.init ); | ||
@@ -40,0 +40,0 @@ } |
+107
-117
@@ -206,10 +206,10 @@ 'use strict'; | ||
| docs: { | ||
| description: description, | ||
| description, | ||
| deprecated: !!deprecated, | ||
| replacedBy: Array.isArray( deprecated ) ? deprecated : undefined | ||
| }, | ||
| fixable: fixable, | ||
| fixable, | ||
| schema: schema || [] | ||
| }, | ||
| create: create | ||
| create | ||
| }; | ||
@@ -340,34 +340,32 @@ } | ||
| return createRule( function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !methods.includes( name ) || | ||
| return createRule( ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !methods.includes( name ) || | ||
| isjQueryConstructor( context, node.callee.object.name ) | ||
| ) { | ||
| return; | ||
| } | ||
| const allowGetOrSet = ( context.options[ 0 ] && context.options[ 0 ].allowGetOrSet ) || 'none'; | ||
| // TODO: nonCollectionReturningValueAccessors have 1 argument in getter mode | ||
| if ( | ||
| ( allowGetOrSet === 'get' && !node.arguments.length ) || | ||
| ) { | ||
| return; | ||
| } | ||
| const allowGetOrSet = ( context.options[ 0 ] && context.options[ 0 ].allowGetOrSet ) || 'none'; | ||
| // TODO: nonCollectionReturningValueAccessors have 1 argument in getter mode | ||
| if ( | ||
| ( allowGetOrSet === 'get' && !node.arguments.length ) || | ||
| ( allowGetOrSet === 'set' && node.arguments.length ) | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| if ( isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| if ( isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| }; | ||
| }, description, options.fixable, options.deprecated, schema ); | ||
| } | ||
| } ), description, options.fixable, options.deprecated, schema ); | ||
| } | ||
@@ -392,22 +390,20 @@ | ||
| return createRule( function ( context ) { | ||
| return { | ||
| 'MemberExpression:exit': function ( node ) { | ||
| const name = node.property.name; | ||
| if ( | ||
| name !== property || | ||
| return createRule( ( context ) => ( { | ||
| 'MemberExpression:exit': ( node ) => { | ||
| const name = node.property.name; | ||
| if ( | ||
| name !== property || | ||
| node.parent.callee === node | ||
| ) { | ||
| return; | ||
| } | ||
| if ( isjQuery( context, node.object ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| }; | ||
| }, description, options.fixable, options.deprecated ); | ||
| if ( isjQuery( context, node.object ) ) { | ||
| context.report( { | ||
| node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| } | ||
| } ), description, options.fixable, options.deprecated ); | ||
| } | ||
@@ -435,24 +431,22 @@ | ||
| return createRule( function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !methods.includes( name ) || | ||
| return createRule( ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( | ||
| !methods.includes( name ) || | ||
| !isjQueryConstructor( context, node.callee.object.name ) | ||
| ) { | ||
| return; | ||
| } | ||
| ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| }; | ||
| }, description, options.fixable, options.deprecated ); | ||
| context.report( { | ||
| node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| } ), description, options.fixable, options.deprecated ); | ||
| } | ||
@@ -477,21 +471,19 @@ | ||
| return createRule( function ( context ) { | ||
| return { | ||
| 'MemberExpression:exit': function ( node ) { | ||
| if ( !isjQueryConstructor( context, node.object.name ) ) { | ||
| return; | ||
| } | ||
| const name = node.property.name; | ||
| if ( name !== property ) { | ||
| return; | ||
| } | ||
| return createRule( ( context ) => ( { | ||
| 'MemberExpression:exit': ( node ) => { | ||
| if ( !isjQueryConstructor( context, node.object.name ) ) { | ||
| return; | ||
| } | ||
| const name = node.property.name; | ||
| if ( name !== property ) { | ||
| return; | ||
| } | ||
| context.report( { | ||
| node: node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| }; | ||
| }, description, options.fixable, options.deprecated ); | ||
| context.report( { | ||
| node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| } ), description, options.fixable, options.deprecated ); | ||
| } | ||
@@ -522,22 +514,20 @@ | ||
| return createRule( function ( context ) { | ||
| return { | ||
| 'CallExpression:exit': function ( node ) { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| const name = node.callee.property.name; | ||
| if ( !methods.includes( name ) ) { | ||
| return; | ||
| } | ||
| if ( isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node: node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| return createRule( ( context ) => ( { | ||
| 'CallExpression:exit': ( node ) => { | ||
| if ( node.callee.type !== 'MemberExpression' ) { | ||
| return; | ||
| } | ||
| }; | ||
| }, description, options.fixable, options.deprecated ); | ||
| const name = node.callee.property.name; | ||
| if ( !methods.includes( name ) ) { | ||
| return; | ||
| } | ||
| if ( isjQuery( context, node.callee ) ) { | ||
| context.report( { | ||
| node, | ||
| message: messageToPlainString( message, node, name, options ), | ||
| fix: options.fix && options.fix.bind( this, node, context ) | ||
| } ); | ||
| } | ||
| } | ||
| } ), description, options.fixable, options.deprecated ); | ||
| } | ||
@@ -561,13 +551,13 @@ | ||
| module.exports = { | ||
| isjQuery: isjQuery, | ||
| isjQueryConstructor: isjQueryConstructor, | ||
| isFunction: isFunction, | ||
| createCollectionMethodRule: createCollectionMethodRule, | ||
| createCollectionPropertyRule: createCollectionPropertyRule, | ||
| createUtilMethodRule: createUtilMethodRule, | ||
| createUtilPropertyRule: createUtilPropertyRule, | ||
| createCollectionOrUtilMethodRule: createCollectionOrUtilMethodRule, | ||
| eventShorthandFixer: eventShorthandFixer, | ||
| jQueryCollectionLink: jQueryCollectionLink, | ||
| jQueryGlobalLink: jQueryGlobalLink | ||
| isjQuery, | ||
| isjQueryConstructor, | ||
| isFunction, | ||
| createCollectionMethodRule, | ||
| createCollectionPropertyRule, | ||
| createUtilMethodRule, | ||
| createUtilPropertyRule, | ||
| createCollectionOrUtilMethodRule, | ||
| eventShorthandFixer, | ||
| jQueryCollectionLink, | ||
| jQueryGlobalLink | ||
| }; |
-359
| # eslint-plugin-no-jquery release history | ||
| ## v2.7.0 | ||
| * New rule: `no-append-html` (#284) (Ed Sanders) | ||
| * New config: Allow rules to disable get/set separately, starting with no-html (Ed Sanders) | ||
| * Deprecated rule: `no-submit`; use `no-event-shorthand` (Ed Sanders) | ||
| — | ||
| * Code: Sort ajax events consistently and alphabetically. (Ed Sanders) | ||
| * Code: utils.isjQuery: Improve `Identifier` detection (#283) (Ed Sanders) | ||
| — | ||
| * Docs: Update eslint-docgen to 0.5.1 (#290) (Ed Sanders) | ||
| * Docs: Show which rules have options, and which are fixable in README (#289) (Ed Sanders) | ||
| * Docs: Fix test links (#280) (Ed Sanders) | ||
| — | ||
| * Release: Update devDependencies (#278) (Ed Sanders) | ||
| ## v2.6.0 | ||
| * New rule: `no-escape-selector` for `$.escapeSelector` util (Ed Sanders) | ||
| * New config: `deprecated-3.6` for new jQuery release (Ed Sanders) | ||
| — | ||
| * Rule fix: Add fixer for `no-on-ready` (Ed Sanders) | ||
| * Rule fix: Add fixer for `no-ready-shorthand` (Ed Sanders) | ||
| * Rule fix: Add fixer for `no-error` (Ed Sanders) | ||
| * Rule fix: Add fixer for `no-parse-xml` (Ed Sanders) | ||
| * Rule fix: Add fixer for `no-parse-html-literal` tag style (Ed Sanders) | ||
| * Rule fix: `no-now`; recommend `Date.now` rather than `(new Date).getTime()` (Ed Sanders) | ||
| — | ||
| * Code: Add real arguments to `no-parse-html` tests (Ed Sanders) | ||
| * Code: codecov.yaml: Remove extra linebreak (Ed Sanders) | ||
| * Release: Update devDependencies (#266) (Ed Sanders) | ||
| ## v2.5.0 | ||
| * New config: `recommended` just includes `variable-pattern` rule (Ed Sanders) | ||
| * New config: `all` covers all usages of jQuery methods and utils (Ed Sanders) | ||
| * New config: Create a `deprecated-X.X` config for every minor release (Ed Sanders) | ||
| * Configs: Use 'warn' instead of 'error' in `deprecated-X` and `all` configs (Ed Sanders) | ||
| * New rule: `no-jquery-constructor` (Ed Sanders) | ||
| — | ||
| * Code: Add `reporthtml` coverage script (Ed Sanders) | ||
| * Code: Remove unnecessary constants (Ed Sanders) | ||
| * Code: Replace `Array#indexOf` with `Array#includes` (Ed Sanders) | ||
| * Code: Only assert error message strings (Ed Sanders) | ||
| * Code: Introduce eslint-plugin-eslint-plugin (Ed Sanders) | ||
| * Code: Add ESLint 7.0.0 support (Ed Sanders) | ||
| * Code: Prefer `$("div")` in test cases (Ed Sanders) | ||
| * Code: Fix ESLint 2.3.0 support (Ed Sanders) | ||
| — | ||
| * Docs: Document and test the `slim` config (Ed Sanders) | ||
| * Docs: Move docs to docs/rules (Ed Sanders) | ||
| * Docs: Suppress more examples with noDoc (no-parse-html-literal) (Ed Sanders) | ||
| * Docs: Update to eslint-docgen 0.3.1 (Ed Sanders) | ||
| * Docs: Suppress some examples with noDoc in long documentation files (Ed Sanders) | ||
| * Docs: Use eslint-docgen (Ed Sanders) | ||
| * Docs: Remove noDoc arg from RuleTesterAndDocs, just use RuleTester (Ed Sanders) | ||
| * Docs: Fetch 'main' path from package.json (Ed Sanders) | ||
| * Docs: Remove extra linebreak from no-parse-html-literal.md (Ed Sanders) | ||
| * Docs: Add missing linebreak before rule source section (Ed Sanders) | ||
| * Docs: Improvements to doc builder (Ed Sanders) | ||
| — | ||
| * Release: Update devDependencies (Ed Sanders) | ||
| ## v2.4.1 | ||
| * Config fix: Fix override of `no-event-shorthand` in `deprecated-3.5` (Ed Sanders) | ||
| — | ||
| * Code: Add real test coverage for index.js (Ed Sanders) | ||
| * Code: gitignore coverage.lcov (Ed Sanders) | ||
| ## v2.4.0 | ||
| * New feature: Add specification of plugin return types to settings (Ed Sanders) | ||
| — | ||
| * New config: Add new `deprecated-3.5` config (Ed Sanders) | ||
| — | ||
| * New rule: `no-find-collection`, split out of `no-find` (Ed Sanders) | ||
| * New rule: `no-find-util`, split out of `no-find` (Ed Sanders) | ||
| — | ||
| * Rule fix: Set all rules to type: `suggestion` (Ed Sanders) | ||
| * Rule fix: `no-global-selector`; add `allowIds` option to allow global selector by ID (Adam Roses Wight) | ||
| * Rule fix: `no-event-shorthand`; add `allowAjaxEvents` option and use in `deprecated-3.3` (Ed Sanders) | ||
| — | ||
| * Docs: Avoid duplicating name in "Prefer..." sentence (Ed Sanders) | ||
| * Docs: Build lists in README.md automatically (Ed Sanders) | ||
| * Docs: Consistently use `.methodOrProp` with collections, not `$.methodOrProp` (Ed Sanders) | ||
| * Docs: Link to jQuery documentation for each method/util/property (Ed Sanders) | ||
| * Docs: Show ruleset information in README (Ed Sanders) | ||
| — | ||
| * Release: State "MIT license" in LICENSE header (Ed Sanders) | ||
| * Release: Update devDependencies (Ed Sanders) | ||
| — | ||
| * Code: Add `#odd` and `#even` to all methods lists, new in jQuery 3.5 (Ed Sanders) | ||
| * Code: Add code coverage checks using Istanbul (Ed Sanders) | ||
| * Code: Move index.js to src/ (Ed Sanders) | ||
| * Code: Restructure files and folders (Ed Sanders) | ||
| * Code: Setup codecov GitHub Action integration (Ed Sanders) | ||
| ## v2.3.2 | ||
| * Rule fix: Add fixer for `no-is-function` (Ed Sanders) | ||
| * Rule fix: Follow-up #186: Actually merge `no-undelegate` into `no-delegate` (Ed Sanders) | ||
| — | ||
| * Docs: Soften and make clearer the language for `no-class-state` (James D. Forrester) | ||
| * Docs: Explain `no-global-selector` restriction more clearly (James D. Forrester) | ||
| — | ||
| * Release: Update devDependencies (Ed Sanders) | ||
| — | ||
| * Code: Remove non-existent $.fn.parse from tests (Ed Sanders) | ||
| ## v2.3.1 | ||
| * New feature: Show deprecation message in linting errors (Ed Sanders) | ||
| — | ||
| * Deprecated rule: `no-die`; use `no-live` (Ed Sanders) | ||
| * Deprecated rule: `no-unbind`; use `no-bind` (Ed Sanders) | ||
| * Deprecated rule: `no-undelegate`; use `no-delegate` (Ed Sanders) | ||
| — | ||
| * Rule fix: Remove `load` from `no-event-shorthand` (Ed Sanders) | ||
| — | ||
| * Docs: Build generic "Prefer" messages for docs when node===true (Ed Sanders) | ||
| * Docs: Escape all code snippets (Ed Sanders) | ||
| * Docs: Monospace rule names (Ed Sanders) | ||
| — | ||
| * Release: Add icons to readme section headings (Ed Sanders) | ||
| * Release: Fix Changelog markdown list spacing (Ed Sanders) | ||
| * Release: Use a limited ruleset for lint-fixing documentation snippets (Ed Sanders) | ||
| — | ||
| * Code: Add `triggerHandler` to `nonCollectionReturningMethods` (Ed Sanders) | ||
| * Code: Check documentation in CI (Ed Sanders) | ||
| * Code: Check rules are listed in README.md & index.js (Ed Sanders) | ||
| * Code: Migrate from Travis to GitHub Actions (James D. Forrester) | ||
| * Code: Remove incorrect TODO comment (Ed Sanders) | ||
| ## v2.3.0 | ||
| * New rule: `variable-pattern` (Ed Sanders) | ||
| * New rule: `no-parse-xml` (Ed Sanders) | ||
| * New rule: `no-visibility` as a group alias for `no-show`, `no-hide`, & `no-toggle` (Ed Sanders) | ||
| — | ||
| * New config: `slim` as a config for users of the jQuery slim build (Ed Sanders) | ||
| — | ||
| * Deprecated rule: `no-show` (Ed Sanders) | ||
| * Deprecated rule: `no-hide` (Ed Sanders) | ||
| * Deprecated rule: `no-toggle` (Ed Sanders) | ||
| — | ||
| * Rule fix: Add `allowDeep` options to `no-extend` (Ed Sanders) | ||
| * Rule fix: Add `hasData` method to `no-data` rule (Ed Sanders) | ||
| * Rule fix: Enforce single tag style in `no-parse-html-literal` (Ed Sanders) | ||
| — | ||
| * New fixer: Add fixer for `no-event-shorthand` and similar (Ed Sanders) | ||
| * New fixer: Add fixer for `no-noop` (Ed Sanders) | ||
| * New fixer: Add fixer for `no-now` (Ed Sanders) | ||
| * New fixer: Add fixer for `no-size` (Ed Sanders) | ||
| — | ||
| * Docs: Link to each rule's definition (Ed Sanders) | ||
| * Docs: Switch `constructorAliases`/`variablePattern` in README (Ed Sanders) | ||
| * Docs: Pad fixer examples so they align (Ed Sanders) | ||
| * Docs: Output example fixes in documentation (Ed Sanders) | ||
| — | ||
| * Release: Update LICENSE authors (Ed Sanders) | ||
| — | ||
| * Code: Add `npm run testpath` for running a single test (Ed Sanders) | ||
| * Code: Add a test that automatically captures all rules (Ed Sanders) | ||
| * Code: Avoid `key in object` lookup (Ed Sanders) | ||
| * Code: Improvements to collection return detection (Ed Sanders) | ||
| * Code: More fixes to jQuery method return types (Ed Sanders) | ||
| * Code: Rename .eslintrc to .eslintrc.json (Ed Sanders) | ||
| * Code: Update eslint-config-wikimedia (Ed Sanders) | ||
| ## v2.2.1 | ||
| * Release: Update index.js and README with missing rules (Ed Sanders) | ||
| ## v2.2.0 | ||
| * New rule: `no-camel-case` (Christophe Coevoet) | ||
| * New rule: `no-constructor-attributes` (Ed Sanders) | ||
| * New rule: `no-contains` (Christophe Coevoet) | ||
| * New rule: `no-error` (Ed Sanders) | ||
| * New rule: `no-is-empty-object` (Ed Sanders) | ||
| * New rule: `no-is-plain-object` (Ed Sanders) | ||
| * New rule: `no-node-name` (Ed Sanders) | ||
| — | ||
| * Rule fix: Add `removeAttr` to `no-attr` rule (Ed Sanders) | ||
| * Rule fix: Add `removeProp` to `no-remove-prop` rule (Ed Sanders) | ||
| * Rule fix: Add ajax method shorthands to `no-ajax-events` and `no-event-shorthand` (Ed Sanders) | ||
| * Rule fix: Detect concatenated selectors in `no-sizzle` (Ed Sanders) | ||
| * Rule fix: Handle concatenated strings and other methods in `no-parse-html-literal` (Ed Sanders) | ||
| * Rule fix: Include the `$.clone` utility in the `no-clone` rule (Ed Sanders) | ||
| * Rule fix: Include the `$.css` utility in the `no-css` rule (Ed Sanders) | ||
| * Rule fix: Make error message in `no-parse-html-literal` less specific (Ed Sanders) | ||
| * Rule fix: Separate out positional sizzle selectors and add to `deprecated-3.4` (Ed Sanders) | ||
| — | ||
| * New fixer: Add fixer for `no-and-self` (Ed Sanders) | ||
| * New fixer: Add fixer for `no-is-array` (Ed Sanders) | ||
| * New fixer: Add fixer for `no-parse-json` (Ed Sanders) | ||
| * New fixer: Add fixer for `no-unique` (Ed Sanders) | ||
| — | ||
| * Docs: Build documentation from tests (Ed Sanders) | ||
| * Docs: Comment in documentation when rules are fixable (Ed Sanders) | ||
| * Docs: Document `npm run doc` (Ed Sanders) | ||
| * Docs: Document when rules are included in a deprecation set (Ed Sanders) | ||
| — | ||
| * Bug: Fix the detection of jQuery collection calls for non-fluent APIs (e.g. `.toArray()`) (Christophe Coevoet) | ||
| * Bug: Support arrow functions (Ed Sanders) | ||
| — | ||
| * Code: Add an EditorConfig config file (Christophe Coevoet) | ||
| * Code: Introduce and use createCollectionOrUtilMethodRule (Ed Sanders) | ||
| * Code: Update development dependencies (Ed Sanders) | ||
| — | ||
| * Release: Add `files` list to package.json (Ed Sanders) | ||
| * Release: Add global settings for configuring jQuery constructor/variable names (Ed Sanders) | ||
| * Release: Update deprecation rulesets (Ed Sanders) | ||
| — | ||
| * Improve messages' references to methods vs. static methods (Christophe Coevoet) | ||
| ## v2.1.0 | ||
| * New rule: `no-class-state` (Ed Sanders) | ||
| — | ||
| * Docs: Fix plugin name (Maurício Meneghini Fauth) | ||
| — | ||
| * Code: Upgrade eslint-config-wikimedia to 0.12.0 (James D. Forrester) | ||
| ## v2.0.0 | ||
| * New rule options: `[{allowScroll:true}]` in `no-animate` (Ed Sanders) | ||
| — | ||
| * Renamed repository, rules and documentation to eslint-plugin-no-jquery (Ed Sanders) | ||
| * Update eslint dev dependency to 5.14.0 (Ed Sanders) | ||
| # Release history as wikimedia/eslint-plugin-jquery | ||
| ## v1.3.2-wmf.6 | ||
| * New rule: `no-box-model` (Ed Sanders) | ||
| * New rule: `no-browser` (Ed Sanders) | ||
| * New rule: `no-context-prop` (Ed Sanders) | ||
| * New rule: `no-error-shorthand` (Ed Sanders) | ||
| * New rule: `no-fx-interval` (Ed Sanders) | ||
| * New rule: `no-hold-ready` (Ed Sanders) | ||
| * New rule: `no-is-numeric` (Ed Sanders) | ||
| * New rule: `no-load-shorthand` (Ed Sanders) | ||
| * New rule: `no-now` (Ed Sanders) | ||
| * New rule: `no-on-ready` (Ed Sanders) | ||
| * New rule: `no-ready-shorthand` (Ed Sanders) | ||
| * New rule: `no-selector-prop` (Ed Sanders) | ||
| * New rule: `no-sub` (Ed Sanders) | ||
| * New rule: `no-support` (Ed Sanders) | ||
| * New rule: `no-unload-shorthand` (Ed Sanders) | ||
| — | ||
| * Bug: Fix `isjQuery` util to match `$`-prefixed properties (Ed Sanders) | ||
| * Bug: Fix `isjQuery` to not match methods of jQuery properties (Ed Sanders) | ||
| * Bug: Only catch `toggle(arg)` if `arg` is definitely not a boolean (Ed Sanders) | ||
| — | ||
| * Code: De-deduplicate rule generation (Ed Sanders) | ||
| * Code: Remove useless export of traverse method (Ed Sanders) | ||
| ## v1.3.2-wmf.5 | ||
| * New rule: `no-animate-toggle` (Ed Sanders) | ||
| * Add "Prefer CSS transitions" to animation rule messages (Ed Sanders) | ||
| * Add " or $.trigger" to `no-event-shorthand` warning (Ed Sanders) | ||
| ## v1.3.2-wmf.4 | ||
| * Fix typo in config listing (Ed Sanders) | ||
| ## v1.3.2-wmf.3 | ||
| * Revert package name, breaking npm package references to instead fix git references (Ed Sanders) | ||
| ## v1.3.2-wmf.2 | ||
| * Provide version-specific deprecation configs (James D. Forrester) | ||
| * Move 'deprecated' config as a pointer to latest, remove old 'slim' config (Ed Sanders) | ||
| — | ||
| * New rule: `no-and-self` (Ed Sanders) | ||
| * New rule: `no-die` and `no-live` (Ed Sanders) | ||
| * New rule: `no-event-shorthand` (Ed Sanders) | ||
| * New rule: `no-global-selector` (Ed Sanders) | ||
| * New rule: `no-is-window` (Ed Sanders) | ||
| * New rule: `no-noop` (Ed Sanders) | ||
| * New rule: `no-parse-html-literal` (Ed Sanders) | ||
| * New rule: `no-parse-json` (Ed Sanders) | ||
| * New rule: `no-type` (Ed Sanders) | ||
| * New rule: `no-unbind` (Ed Sanders) | ||
| * New rule: `no-undelegate` (Ed Sanders) | ||
| * New rule: `no-unique` (Ed Sanders) | ||
| — | ||
| * Miscellaneous release-related clean-up (James D. Forrester) | ||
| ## v1.3.2-wmf.1 | ||
| * New rule: `no-is-array` (Mackie Underdown) | ||
| * New rule: `no-is-function` (Brendan Abbott; renamed by Ed Sanders pre-release) | ||
| * New rule: `no-extend` (Brendan Abbott) | ||
| * New rule: `no-grep` (Ed Sanders) | ||
| * New rule: `no-each-collection` (Ed Sanders) | ||
| * New rule: `no-each-util` (Ed Sanders) | ||
| * New rule: `no-map-collection` (Ed Sanders) | ||
| * New rule: `no-map-util` (Ed Sanders) | ||
| — | ||
| * Deprecated rule: `no-each` (Ed Sanders) | ||
| * Deprecated rule: `no-map` (Ed Sanders) | ||
| — | ||
| * Code: Update development dependencies (David Graham) | ||
| * Code: Refactor to use new rule format (Ed Sanders) | ||
| — | ||
| * README: Note that this is a fork (James D. Forrester) |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
92334
-13.27%2693
-1.5%