eslint-plugin-no-jquery
Advanced tools
Comparing version
{ | ||
"name": "eslint-plugin-no-jquery", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Disallow jQuery functions with native equivalents.", | ||
@@ -37,3 +37,3 @@ "repository": { | ||
"codecov": "^3.8.3", | ||
"eslint-config-wikimedia": "^0.28.0", | ||
"eslint-config-wikimedia": "^0.28.2", | ||
"eslint-docgen": "^0.7.1", | ||
@@ -40,0 +40,0 @@ "eslint-plugin-eslint-plugin": "^6.1.0", |
@@ -110,2 +110,3 @@ <!-- This file is built by build-readme.js. Do not edit it directly; edit README.md.template instead. --> | ||
* [`no-jquery/no-delegate`](docs/rules/no-delegate.md) `3.0`, `all` | ||
* [`no-jquery/no-done-fail`](docs/rules/no-done-fail.md) `all` | ||
* [`no-jquery/no-each`](docs/rules/no-each.md) | ||
@@ -124,2 +125,3 @@ * [`no-jquery/no-each-collection`](docs/rules/no-each-collection.md) `all` | ||
* [`no-jquery/no-find-util`](docs/rules/no-find-util.md) `all` | ||
* [`no-jquery/no-fx`](docs/rules/no-fx.md) `slim` | ||
* [`no-jquery/no-fx-interval`](docs/rules/no-fx-interval.md) `3.0` | ||
@@ -126,0 +128,0 @@ * [`no-jquery/no-global-eval`](docs/rules/no-global-eval.md) `all` |
@@ -28,2 +28,3 @@ 'use strict'; | ||
'no-die': require( './rules/no-die' ), | ||
'no-done-fail': require( './rules/no-done-fail' ), | ||
'no-each': require( './rules/no-each' ), | ||
@@ -42,2 +43,3 @@ 'no-each-collection': require( './rules/no-each-collection' ), | ||
'no-find-util': require( './rules/no-find-util' ), | ||
'no-fx': require( './rules/no-fx' ), | ||
'no-fx-interval': require( './rules/no-fx-interval' ), | ||
@@ -122,2 +124,3 @@ 'no-global-eval': require( './rules/no-global-eval' ), | ||
'no-jquery/no-slide': 'error', | ||
'no-jquery/no-fx': 'error', | ||
// Ajax | ||
@@ -339,4 +342,6 @@ 'no-jquery/no-ajax': 'error', | ||
'no-jquery/no-sub': 'warn', | ||
'no-jquery/no-text': 'warn' | ||
'no-jquery/no-text': 'warn', | ||
// Other methods | ||
'no-jquery/no-done-fail': 'warn' | ||
} | ||
@@ -343,0 +348,0 @@ } |
@@ -5,2 +5,4 @@ 'use strict'; | ||
const methods = [ 'animate', 'stop', 'finish' ]; | ||
module.exports = { | ||
@@ -11,4 +13,4 @@ meta: { | ||
description: | ||
'Disallows the ' + utils.jQueryCollectionLink( 'animate' ) + | ||
' method. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.' | ||
'Disallows the ' + methods.map( utils.jQueryCollectionLink ).join( '/' ) + | ||
' methods. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.' | ||
}, | ||
@@ -32,3 +34,3 @@ schema: [ | ||
node.callee.type !== 'MemberExpression' || | ||
node.callee.property.name !== 'animate' | ||
!methods.includes( node.callee.property.name ) | ||
) { | ||
@@ -38,3 +40,3 @@ return; | ||
const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll; | ||
if ( allowScroll ) { | ||
if ( node.callee.property.name === 'animate' && allowScroll ) { | ||
const arg = node.arguments[ 0 ]; | ||
@@ -41,0 +43,0 @@ // Check properties list has more than just scrollTop/scrollLeft |
@@ -47,4 +47,5 @@ 'use strict'; | ||
'mouseover', | ||
'mouseup' | ||
].concat( ajaxEvents ), | ||
'mouseup', | ||
...ajaxEvents | ||
], | ||
( node ) => node === true ? | ||
@@ -51,0 +52,0 @@ 'Use the `allowAjaxEvents` option to allow `ajax*` methods. Prefer `.on` or `.trigger`' : |
@@ -51,3 +51,5 @@ 'use strict'; | ||
fix: function ( fixer ) { | ||
if ( !isDeep ) { | ||
// Only auto-fix if we are sure the first argument is an object. | ||
// If it is undefined or null variable, then Object.assign will throw. | ||
if ( !isDeep && node.arguments[ 0 ] && node.arguments[ 0 ].type === 'ObjectExpression' ) { | ||
return fixer.replaceText( node.callee, 'Object.assign' ); | ||
@@ -54,0 +56,0 @@ } |
@@ -176,2 +176,3 @@ 'use strict'; | ||
function isjQuery( context, node ) { | ||
// eslint-disable-next-line security/detect-non-literal-regexp | ||
const variablePattern = new RegExp( | ||
@@ -315,3 +316,3 @@ ( context.settings && context.settings[ 'no-jquery' ] && context.settings[ 'no-jquery' ].variablePattern ) || | ||
let description = 'Disallows the ' + methods.map( jQueryCollectionLink ).join( '/' ) + ' ' + | ||
( methods.length > 1 ? 'methods' : 'method' ) + '.'; | ||
( methods.length > 1 ? 'methods' : 'method' ) + '.'; | ||
@@ -374,3 +375,3 @@ description += messageSuffix( message ); | ||
/** | ||
* Create a rule for collection property | ||
* Create a rule for collection properties | ||
* | ||
@@ -427,3 +428,3 @@ * @param {string} property Property name | ||
let description = 'Disallows the ' + methods.map( jQueryGlobalLink ).join( '/' ) + ' ' + | ||
( methods.length > 1 ? 'utilies' : 'utility' ) + '.'; | ||
( methods.length > 1 ? 'utilies' : 'utility' ) + '.'; | ||
@@ -455,3 +456,3 @@ description += messageSuffix( message ); | ||
/** | ||
* Create a rule for util methods | ||
* Create a rule for util properties | ||
* | ||
@@ -507,3 +508,3 @@ * @param {string} property Property name | ||
let description = 'Disallows the ' + methods.map( jQueryCollectionLink ).join( '/' ) + ' ' + | ||
( methods.length > 1 ? 'methods' : 'method' ); | ||
( methods.length > 1 ? 'methods' : 'method' ); | ||
@@ -535,2 +536,43 @@ description += ' and ' + methods.map( jQueryGlobalLink ).join( '/' ) + ' ' + | ||
/** | ||
* Create a rule for a method on any object | ||
* | ||
* @param {string|string[]} methods Method or list of method names | ||
* @param {string|Function} message Message to report. See createCollectionMethodRule. | ||
* @param {Function} linkGenerator Function to generate a markdown link | ||
* @param {Object} [options] Options. See createCollectionMethodRule. | ||
* for a given function name. | ||
* @return {Object} Rule | ||
*/ | ||
function createUniversalMethodRule( methods, message, linkGenerator, options ) { | ||
options = options || {}; | ||
options.mode = 'util'; | ||
methods = Array.isArray( methods ) ? methods : [ methods ]; | ||
let description = 'Disallows the ' + methods.map( linkGenerator ).join( '/' ) + ' ' + | ||
( methods.length > 1 ? 'methods' : 'method' ) + '.'; | ||
description += messageSuffix( message ); | ||
return createRule( ( context ) => ( { | ||
'CallExpression:exit': ( node ) => { | ||
if ( node.callee.type !== 'MemberExpression' ) { | ||
return; | ||
} | ||
const name = node.callee.property.name; | ||
if ( !methods.includes( name ) ) { | ||
return; | ||
} | ||
context.report( { | ||
node, | ||
message: messageToPlainString( message, node, name, options ), | ||
fix: options.fix && options.fix.bind( this, node, context ) | ||
} ); | ||
} | ||
} ), description, options.fixable, options.deprecated ); | ||
} | ||
function eventShorthandFixer( node, context, fixer ) { | ||
@@ -589,2 +631,3 @@ const name = node.callee.property.name; | ||
createCollectionOrUtilMethodRule, | ||
createUniversalMethodRule, | ||
eventShorthandFixer, | ||
@@ -591,0 +634,0 @@ jQueryCollectionLink, |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
95466
2.97%110
1.85%2780
2.92%216
0.93%