Skip to content

Commit 24e4cd9

Browse files
�[200~docs: add inline comments to ESLint config for clarity
1 parent 7a35455 commit 24e4cd9

File tree

1 file changed

+65
-25
lines changed

1 file changed

+65
-25
lines changed

javascript/selenium-webdriver/eslint.config.js

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,93 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17+
// ESLint configuration for the Selenium project using flat config format
1718

18-
const globals = require('globals')
19-
const noOnlyTests = require('eslint-plugin-no-only-tests')
20-
const js = require('@eslint/js')
21-
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended')
22-
const mochaPlugin = require('eslint-plugin-mocha')
23-
const nodePlugin = require('eslint-plugin-n')
19+
// Import required plugin configurations and utilities
20+
const globals = require('globals') // Provides global variables for different environments
21+
const noOnlyTests = require('eslint-plugin-no-only-tests') // Prevents usage of `.only` in test cases
22+
const js = require('@eslint/js') // ESLint's recommended JavaScript config
23+
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended') // Integrates Prettier with ESLint
24+
const mochaPlugin = require('eslint-plugin-mocha') // Linting rules specific to Mocha test framework
25+
const nodePlugin = require('eslint-plugin-n') // Linting rules for Node.js environment
2426

2527
module.exports = [
28+
// Base JavaScript linting rules
2629
js.configs.recommended,
30+
31+
// Enforce Prettier formatting as ESLint rules
2732
eslintPluginPrettierRecommended,
33+
34+
// Recommended rules for Mocha
2835
mochaPlugin.configs.flat.recommended,
36+
37+
// Recommended Node.js rules for scripts
2938
nodePlugin.configs['flat/recommended-script'],
39+
3040
{
41+
// Define language environment and parser settings
3142
languageOptions: {
3243
globals: {
33-
mocha: true,
34-
es6: true,
35-
...globals.node,
44+
mocha: true, // Enable global Mocha variables like `describe`, `it`, etc.
45+
es6: true, // Enable ES6 globals like `Set`, `Map`, etc.
46+
...globals.node, // Merge Node.js specific globals
3647
},
3748
parserOptions: {
38-
ecmaVersion: 2022,
49+
ecmaVersion: 2022, // Use modern JavaScript syntax (ES2022)
3950
},
4051
},
52+
53+
// File patterns this config applies to
4154
files: ['**/*.js', 'lib/http.js'],
55+
56+
// Files/folders to ignore during linting
4257
ignores: ['node_modules/*', 'generator/*', 'devtools/generator/'],
58+
59+
// Plugins used
4360
plugins: {
44-
'no-only-tests': noOnlyTests,
61+
'no-only-tests': noOnlyTests, // Plugin to prevent `.only` in tests
4562
},
63+
64+
// Custom rule configuration
4665
rules: {
66+
// Disallow reassignment of `const` variables
4767
'no-const-assign': 'error',
68+
69+
// Disallow using `this` before calling `super()` in constructors
4870
'no-this-before-super': 'error',
71+
72+
// Disallow usage of undeclared variables
4973
'no-undef': 'error',
74+
75+
// Disallow unreachable code after `return`, `throw`, `continue`, or `break`
5076
'no-unreachable': 'error',
77+
78+
// Disallow unused variables, with exceptions for those starting with `_`
5179
'no-unused-vars': [
5280
'error',
5381
{
54-
varsIgnorePattern: '^_',
82+
varsIgnorePattern: '^_', // Ignore variables like `_unused`
5583
args: 'all',
5684
argsIgnorePattern: '^_',
5785
},
5886
],
87+
88+
// Require `super()` call in constructors if extending another class
5989
'constructor-super': 'error',
90+
91+
// Enforce correct usage of `typeof` comparisons
6092
'valid-typeof': 'error',
93+
94+
// Prevent committing `.only` in tests (e.g., `it.only()`, `describe.only()`)
6195
'no-only-tests/no-only-tests': 'error',
62-
'n/no-deprecated-api': ['error'],
63-
'n/no-missing-import': ['error'],
64-
'n/no-missing-require': ['error'],
65-
'n/no-mixed-requires': ['error'],
66-
'n/no-new-require': ['error'],
67-
'n/no-unpublished-import': ['error'],
96+
97+
// Node.js plugin rules for preventing common issues
98+
'n/no-deprecated-api': ['error'], // Disallow use of deprecated Node.js APIs
99+
'n/no-missing-import': ['error'], // Disallow importing modules that don't exist
100+
'n/no-missing-require': ['error'], // Same as above for `require`
101+
'n/no-mixed-requires': ['error'], // Enforce either all `require` at top or dynamic—not both
102+
'n/no-new-require': ['error'], // Disallow `new require(...)` statements
103+
'n/no-unpublished-import': ['error'], // Disallow importing modules not listed in `package.json`
68104
'n/no-unpublished-require': [
69105
'error',
70106
{
@@ -76,10 +112,12 @@ module.exports = [
76112
'eslint-plugin-n',
77113
'eslint-plugin-no-only-tests',
78114
],
79-
tryExtensions: ['.js'],
115+
tryExtensions: ['.js'], // Only check JS files
80116
},
81117
],
82-
'n/prefer-node-protocol': ['error'],
118+
'n/prefer-node-protocol': ['error'], // Prefer `node:` protocol for built-in Node.js modules
119+
120+
// Disable specific Mocha rules (likely due to project style)
83121
'mocha/no-skipped-tests': ['off'],
84122
'mocha/no-mocha-arrows': ['off'],
85123
'mocha/no-setup-in-describe': ['off'],
@@ -92,14 +130,16 @@ module.exports = [
92130
'mocha/no-nested-tests': ['off'],
93131
'mocha/no-pending-tests': ['off'],
94132
'mocha/no-identical-title': ['off'],
133+
134+
// Prettier-specific formatting rules
95135
'prettier/prettier': [
96136
'error',
97137
{
98-
endOfLine: 'lf',
99-
printWidth: 120,
100-
semi: false,
101-
singleQuote: true,
102-
trailingComma: 'all',
138+
endOfLine: 'lf', // Use line feed only
139+
printWidth: 120, // Max line width
140+
semi: false, // No semicolons
141+
singleQuote: true, // Use single quotes
142+
trailingComma: 'all', // Use trailing commas wherever possible
103143
},
104144
],
105145
},

0 commit comments

Comments
 (0)