🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

eslint-plugin-no-jquery

Package Overview
Dependencies
Maintainers
25
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-jquery - npm Package Compare versions

Comparing version

to
3.0.0

src/.eslintrc.js

21

package.json
{
"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 @@ },

@@ -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',

@@ -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 }

@@ -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' &&

@@ -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' )
}
);

@@ -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 @@ }

@@ -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
};

Sorry, the diff of this file is not supported yet