Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code: Use object shorthand for properties #315

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"eslint-plugin/require-meta-docs-url": "off",
"eslint-plugin/test-case-property-ordering": [ "error",
[ "code", "options", "parserOptions", "settings", "errors", "output" ]
]
],
"object-shorthand": [ "error", "properties" ]
}
}
2 changes: 1 addition & 1 deletion src/rules/no-ajax-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
}
if ( usedMethod && utils.isjQuery( context, node ) ) {
context.report( {
node: node,
node,
message: 'Prefer local event to {{method}}',
data: { method: usedMethod }
} );
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-animate-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {

if ( utils.isjQuery( context, node ) ) {
context.report( {
node: node,
node,
message: 'Prefer CSS transitions to .{{method}}',
data: { method: node.callee.property.name }
} );
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {

if ( utils.isjQuery( context, node ) ) {
context.report( {
node: node,
node,
message: allowScroll ?
'Prefer CSS transitions to .animate' :
'Prefer CSS transitions or CSS scroll-behaviour to .animate'
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-append-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {

if ( utils.isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-class-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {

if ( utils.isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: 'Where possible, maintain application state in JS to avoid slower DOM queries'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-constructor-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
}

context.report( {
node: node,
node,
message: 'Prefer .attr to constructor attributes'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
}

context.report( {
node: node,
node,
message: 'Prefer Promise to $.Deferred'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
}

context.report( {
node: node,
node,
message: 'Prefer Object.assign or the spread operator to $.extend',
fix: function ( fixer ) {
if ( !isDeep ) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-fx-interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
}

context.report( {
node: node,
node,
message: '$.fx.interval is not allowed'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-global-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
}

context.report( {
node: node,
node,
message: 'Avoid queries which search the entire DOM. Keep DOM nodes in memory where possible.'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-jquery-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
}

context.report( {
node: node,
node,
message: 'The jQuery constructor is not allowed'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-load-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {

if ( utils.isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: 'Prefer .on or .trigger to .load',
fix: utils.eventShorthandFixer.bind( this, node, context )
} );
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-on-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {

if ( utils.isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: '.on("ready") is not allowed',
fix: ( fixer ) => ( node.arguments.length > 1 ) ?
[
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-other-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ module.exports = {
}
if ( utils.isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: '.{{name}} is not allowed',
data: { name: name }
data: { name }
} );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-other-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ module.exports = {
}

context.report( {
node: node,
node,
message: '$.{{name}} is not allowed',
data: { name: name }
data: { name }
} );
}
} )
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-parse-html-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ module.exports = {
}

context.report( {
node: node,
message: message,
node,
message,
fix: ( fixer ) => expectedTag ? fixer.replaceText( arg, '"' + expectedTag + '"' ) : null
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
'CallExpression:exit': ( node ) => {
if ( isDirect( context, node ) || isChained( context, node ) ) {
context.report( {
node: node,
node,
message: '.ready is not allowed'
} );
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ module.exports = {

if ( !allowPositional && forbiddenPositional.test( value ) ) {
context.report( {
node: node,
node,
message: 'Positional selector extensions are not allowed'
} );
} else if ( !allowOther && forbiddenOther.test( value ) ) {
context.report( {
node: node,
node,
message: 'Selector extensions are not allowed'
} );
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/variable-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
right && utils.isjQuery( context, right )
) {
context.report( {
node: node,
node,
message: 'jQuery collection names must match the variablePattern'
} );
}
Expand Down
38 changes: 19 additions & 19 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
//
// Returns true if the function call node is attached to a jQuery element set.
function isjQuery( context, node ) {
const variablePattern = new RegExp(

Check warning on line 176 in src/utils.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Found non-literal argument to RegExp Constructor

Check warning on line 176 in src/utils.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Found non-literal argument to RegExp Constructor

Check warning on line 176 in src/utils.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Found non-literal argument to RegExp Constructor

Check warning on line 176 in src/utils.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Found non-literal argument to RegExp Constructor

Check warning on line 176 in src/utils.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Found non-literal argument to RegExp Constructor

Check warning on line 176 in src/utils.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Found non-literal argument to RegExp Constructor
( context.settings && context.settings[ 'no-jquery' ] && context.settings[ 'no-jquery' ].variablePattern ) ||
'^\\$.'
);
Expand Down Expand Up @@ -203,14 +203,14 @@
meta: {
type: 'suggestion',
docs: {
description: description,
description,
deprecated: !!deprecated,
replacedBy: Array.isArray( deprecated ) ? deprecated : undefined
},
fixable: fixable,
fixable,
schema: schema || []
},
create: create
create
};
}

Expand Down Expand Up @@ -359,7 +359,7 @@

if ( isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: messageToPlainString( message, node, name, options ),
fix: options.fix && options.fix.bind( this, node, context )
} );
Expand Down Expand Up @@ -396,7 +396,7 @@
}
if ( isjQuery( context, node.object ) ) {
context.report( {
node: node,
node,
message: messageToPlainString( message, node, name, options ),
fix: options.fix && options.fix.bind( this, node, context )
} );
Expand Down Expand Up @@ -439,7 +439,7 @@
}

context.report( {
node: node,
node,
message: messageToPlainString( message, node, name, options ),
fix: options.fix && options.fix.bind( this, node, context )
} );
Expand Down Expand Up @@ -475,7 +475,7 @@
}

context.report( {
node: node,
node,
message: messageToPlainString( message, node, name, options ),
fix: options.fix && options.fix.bind( this, node, context )
} );
Expand Down Expand Up @@ -517,7 +517,7 @@
}
if ( isjQuery( context, node.callee ) ) {
context.report( {
node: node,
node,
message: messageToPlainString( message, node, name, options ),
fix: options.fix && options.fix.bind( this, node, context )
} );
Expand All @@ -542,15 +542,15 @@
}

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
};
2 changes: 1 addition & 1 deletion tests/rules/no-event-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ ruleTester.run( 'no-event-shorthand', rule, {
options: [ { allowAjaxEvents: true } ]
} ) )
),
invalid: invalid
invalid
} );
Loading