Skip to content

Commit 12e28c2

Browse files
authoredApr 11, 2025··
Merge pull request #272 from magento-gl/AC-13683-v1
AC-13683::Investigate latest major version of grunt-eslint
2 parents d7ece6d + 4d17750 commit 12e28c2

18 files changed

+790
-611
lines changed
 

‎.github/workflows/php.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Setup node
2626
uses: actions/setup-node@v2
2727
with:
28-
node-version: '16'
28+
node-version: '21'
2929

3030
- uses: actions/checkout@v2
3131

@@ -65,7 +65,7 @@ jobs:
6565
- name: Setup node
6666
uses: actions/setup-node@v2
6767
with:
68-
node-version: '16'
68+
node-version: '21'
6969

7070
- uses: actions/checkout@v2
7171

@@ -82,7 +82,7 @@ jobs:
8282
- name: Setup node
8383
uses: actions/setup-node@v2
8484
with:
85-
node-version: '16'
85+
node-version: '21'
8686

8787
- uses: actions/checkout@v2
8888

‎eslint/.eslintrc

-8
This file was deleted.

‎eslint/.eslintrc-jquery

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"ignorePatterns": ["**/vendor/**/*.js", "**/node_modules/**/*.js"],
33
"rules": {
4-
"jquery-no-andSelf": 2,
5-
"jquery-no-bind-unbind": 2,
6-
"jquery-no-input-event-shorthand": 2,
7-
"jquery-no-delegate-undelegate": 2,
8-
"jquery-no-event-shorthand": 2,
9-
"jquery-no-size": 2,
10-
"jquery-no-trim": 2,
11-
"jquery-no-misc-deprecated-functions": 2,
12-
"jquery-no-deprecated-expr": 2
4+
"magento-coding-standard-eslint-plugin/jquery-no-andSelf": 2,
5+
"magento-coding-standard-eslint-plugin/jquery-no-bind-unbind": 2,
6+
"magento-coding-standard-eslint-plugin/jquery-no-input-event-shorthand": 2,
7+
"magento-coding-standard-eslint-plugin/jquery-no-delegate-undelegate": 2,
8+
"magento-coding-standard-eslint-plugin/jquery-no-event-shorthand": 2,
9+
"magento-coding-standard-eslint-plugin/jquery-no-size": 2,
10+
"magento-coding-standard-eslint-plugin/jquery-no-trim": 2,
11+
"magento-coding-standard-eslint-plugin/jquery-no-misc-deprecated-functions": 2,
12+
"magento-coding-standard-eslint-plugin/jquery-no-deprecated-expr": 2
1313
}
1414
}

‎eslint/eslint.config.mjs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* ESLint Configuration for Magento Project
3+
*
4+
* This configuration extends Magento, jQuery, and reset ESLint rules,
5+
* while enforcing Magento coding standards using the `magento-coding-standard-eslint-plugin`.
6+
* It uses FlatCompat to handle multiple config files in a modular way.
7+
*/
8+
9+
import { defineConfig } from "eslint/config";
10+
import magentoCodingStandardEslintPlugin from "magento-coding-standard-eslint-plugin";
11+
import path from "node:path";
12+
import { fileURLToPath } from "node:url";
13+
import js from "@eslint/js";
14+
import { FlatCompat } from "@eslint/eslintrc";
15+
16+
const __filename = fileURLToPath(import.meta.url);
17+
const __dirname = path.dirname(__filename);
18+
const compat = new FlatCompat({
19+
baseDirectory: __dirname,
20+
recommendedConfig: js.configs.recommended,
21+
allConfig: js.configs.all
22+
});
23+
export default defineConfig([{
24+
extends: compat.extends(
25+
"./.eslintrc-reset", // Resets all rules before applying custom ones
26+
"./.eslintrc-magento", // Magento-specific coding standards
27+
"./.eslintrc-jquery", // jQuery-related ESLint Rules
28+
"./.eslintrc-misc", // Miscellaneous Rules
29+
),
30+
plugins: {
31+
"magento-coding-standard-eslint-plugin": magentoCodingStandardEslintPlugin, // This is in flat config format (object)
32+
}
33+
}]);

‎eslint/index.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* ESLint Plugin for jQuery Deprecation Rules
3+
* This module aggregates individual jQuery-related rules into a single .
4+
*/
5+
import jqueryNoAndSelf from './rules/jquery-no-andSelf.js';
6+
import jqueryNoBindUnbind from './rules/jquery-no-bind-unbind.js';
7+
import jqueryNoDelegateUndelegate from './rules/jquery-no-delegate-undelegate.js';
8+
import jqueryNoDeprecatedExpr from './rules/jquery-no-deprecated-expr.js';
9+
import jqueryNoEventShorthand from './rules/jquery-no-event-shorthand.js';
10+
import jqueryNoInputEventShorthand from './rules/jquery-no-input-event-shorthand.js';
11+
import jqueryNoMiscDeprecatedFunctions from './rules/jquery-no-misc-deprecated-functions.js';
12+
import jqueryNoSize from './rules/jquery-no-size.js';
13+
import jqueryNoTrim from './rules/jquery-no-trim.js';
14+
15+
export default {
16+
rules: {
17+
'jquery-no-andSelf': jqueryNoAndSelf,
18+
'jquery-no-bind-unbind': jqueryNoBindUnbind,
19+
'jquery-no-delegate-undelegate': jqueryNoDelegateUndelegate,
20+
'jquery-no-deprecated-expr': jqueryNoDeprecatedExpr,
21+
'jquery-no-event-shorthand': jqueryNoEventShorthand,
22+
'jquery-no-input-event-shorthand': jqueryNoInputEventShorthand,
23+
'jquery-no-misc-deprecated-functions': jqueryNoMiscDeprecatedFunctions,
24+
'jquery-no-size': jqueryNoSize,
25+
'jquery-no-trim': jqueryNoTrim
26+
}
27+
};

‎eslint/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "magento-coding-standard-eslint-plugin",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"resolutions": {
6+
"eslint": "~9.22.0"
7+
},
8+
"eslintConfig": {
9+
"plugins": ["magento-coding-standard-eslint-plugin"]
10+
},
11+
"type": "module"
12+
}

‎eslint/rules/jquery-no-andSelf.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -20,10 +23,6 @@ module.exports = {
2023
* @returns {Object}
2124
*/
2225
create: function (context) {
23-
'use strict';
24-
25-
var utils = require('./utils.js');
26-
2726
return {
2827
/**
2928
* Checks if andSelf is used in the node and reports it.

‎eslint/rules/jquery-no-bind-unbind.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -20,10 +23,6 @@ module.exports = {
2023
* @returns {Object}
2124
*/
2225
create: function (context) {
23-
'use strict';
24-
25-
var utils = require('./utils.js');
26-
2726
return {
2827
/**
2928
* Checks if bind and unbind are used in the node and reports it.

‎eslint/rules/jquery-no-delegate-undelegate.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -20,10 +23,6 @@ module.exports = {
2023
* @returns {Object}
2124
*/
2225
create: function (context) {
23-
'use strict';
24-
25-
var utils = require('./utils.js');
26-
2726
return {
2827
/**
2928
* Checks if delegate and undelegate are used in the node and reports it.

‎eslint/rules/jquery-no-deprecated-expr.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -17,10 +20,6 @@ module.exports = {
1720
* @returns {Object}
1821
*/
1922
create: function (context) {
20-
'use strict';
21-
22-
var utils = require('./utils.js');
23-
2423
return {
2524
/**
2625
* Checks for jQuery.expr[':']

‎eslint/rules/jquery-no-event-shorthand.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -17,10 +20,6 @@ module.exports = {
1720
* @returns {Object}
1821
*/
1922
create: function (context) {
20-
'use strict';
21-
22-
var utils = require('./utils.js');
23-
2423
return {
2524
/**
2625
* Checks if shorthand event methods are used.

‎eslint/rules/jquery-no-input-event-shorthand.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -17,10 +20,6 @@ module.exports = {
1720
* @returns {Object}
1821
*/
1922
create: function (context) {
20-
'use strict';
21-
22-
var utils = require('./utils.js');
23-
2423
return {
2524
/**
2625
* Checks if shortcuts are used to trigger events and reports it.

‎eslint/rules/jquery-no-misc-deprecated-functions.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -17,10 +20,6 @@ module.exports = {
1720
* @returns {Object}
1821
*/
1922
create: function (context) {
20-
'use strict';
21-
22-
var utils = require('./utils.js');
23-
2423
return {
2524
/**
2625
* Checks if deprecated methods are used and reports it.

‎eslint/rules/jquery-no-size.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -20,10 +23,6 @@ module.exports = {
2023
* @returns {Object}
2124
*/
2225
create: function (context) {
23-
'use strict';
24-
25-
var utils = require('./utils.js');
26-
2726
return {
2827
/**
2928
* Checks if size method is used and reports it.

‎eslint/rules/jquery-no-trim.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
// Import utils using ES module syntax
2+
import utils from './utils.js';
3+
4+
export default {
25
meta: {
36
type: 'suggestion',
47
docs: {
@@ -20,10 +23,6 @@ module.exports = {
2023
* @returns {Object}
2124
*/
2225
create: function (context) {
23-
'use strict';
24-
25-
var utils = require('./utils.js');
26-
2726
return {
2827
/**
2928
* Checks if trim method is used and reports it.

‎eslint/rules/utils.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @returns object
55
*/
66
function define(node) {
7-
'use strict';
87
var defineStmt, args;
98

109
defineStmt = node.body.find(function (stmt) {
@@ -36,7 +35,6 @@ function define(node) {
3635
* @returns {null|*}
3736
*/
3837
function getJqueryName(defineObject) {
39-
'use strict';
4038

4139
var jQueryPathIndex;
4240

@@ -57,7 +55,6 @@ function getJqueryName(defineObject) {
5755
* Get Root Program node
5856
*/
5957
function getProgramNode(node) {
60-
'use strict';
6158
if (!node.parent) {
6259
return node;
6360
}
@@ -71,7 +68,6 @@ function getProgramNode(node) {
7168
* @returns {Object|Null}
7269
*/
7370
function getExpressionId(node) {
74-
'use strict';
7571

7672
while (node) {
7773
switch (node.type) {
@@ -102,7 +98,6 @@ function getExpressionId(node) {
10298
*/
10399

104100
function isjQuery(node) {
105-
'use strict';
106101
var parentNode, defineNode, jQueryId, id;
107102

108103
parentNode = getProgramNode(node);
@@ -116,7 +111,7 @@ function isjQuery(node) {
116111
return id && jQueryId && id.name === jQueryId.name;
117112
}
118113

119-
module.exports = {
114+
export default {
120115
traverse: getExpressionId,
121116
isjQuery: isjQuery
122117
};

0 commit comments

Comments
 (0)
Please sign in to comment.