Skip to content

Commit fb7d594

Browse files
authored
style: apply neostandard to JS files (#1380)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 53607e2 commit fb7d594

File tree

5 files changed

+106
-90
lines changed

5 files changed

+106
-90
lines changed

eslint.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
import path from 'node:path'
2121
import { fileURLToPath } from 'node:url'
2222

23-
import { default as baseCfg, globals } from './tools/code-style/eslint.config.mjs'
23+
import baseCfg, { globals } from './tools/code-style/eslint.config.mjs'
2424

2525
const __filename = fileURLToPath(import.meta.url)
2626
const __dirname = path.dirname(__filename)
@@ -36,7 +36,7 @@ export default [
3636
{
3737
name: 'project-specific',
3838
rules: {
39-
"complexity": ["error", { "max": 15 }]
39+
complexity: ['error', { max: 15 }]
4040
}
4141
},
4242
{
@@ -91,7 +91,7 @@ export default [
9191
'docs/.venv/',
9292
'examples/**/dist/',
9393
'tools/',
94-
'tests/integration/'
94+
'tests/integration/*/'
9595
],
9696
},
9797
]

tests/integration/index.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
const fs = require('fs')
21-
const path = require('path')
22-
const { spawnSync } = require('child_process')
20+
const { spawnSync } = require('node:child_process')
21+
const fs = require('node:fs')
22+
const path = require('node:path')
2323

2424
const { describe, expect, it } = require('@jest/globals')
2525

@@ -335,6 +335,7 @@ describe('integration', () => {
335335
* @param {string} format
336336
* @param {*} data
337337
* @returns {string}
338+
* @throws {RangeError} if format is unsupported
338339
*/
339340
function makeReproducible (format, data) {
340341
switch (format.toLowerCase()) {

tests/integration/setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
const { spawnSync } = require('child_process')
21-
const path = require('path')
20+
const { spawnSync } = require('node:child_process')
21+
const path = require('node:path')
2222

2323
const nodeSV = Object.freeze((process?.versions?.node ?? '').split('.').map(Number));
2424

tools/code-style/eslint.config.mjs

Lines changed: 96 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
import path from 'node:path'
2121
import { fileURLToPath } from 'node:url'
2222

23-
import plugin_js from '@eslint/js'
23+
/* eslint-disable camelcase -- readability */
2424
import config_love from 'eslint-config-love'
2525
import plugin_import from 'eslint-plugin-import'
2626
import plugin_jsdoc from 'eslint-plugin-jsdoc'
@@ -29,36 +29,52 @@ import plugin_n from 'eslint-plugin-n'
2929
import plugin_simpleImportSort from 'eslint-plugin-simple-import-sort'
3030
import plugin_tsdoc from 'eslint-plugin-tsdoc'
3131
import globals from 'globals'
32+
import config_neostandard from 'neostandard'
3233

3334
const __filename = fileURLToPath(import.meta.url)
3435
const __dirname = path.dirname(__filename)
3536
const projectRoot = path.dirname(path.dirname(__dirname))
3637

37-
3838
const licenseHeaderFile = path.join(projectRoot, '.license-header.js')
3939

40-
/* eslint-disable jsdoc/valid-types */
40+
/* eslint-disable jsdoc/valid-types -- type-import not supported yet */
4141

4242
/**
43-
* @type {import('eslint').Linter.Config[]}
44-
* @see https://eslint.org
43+
* @typedef {import('eslint').Linter.Config} Config
44+
*/
45+
46+
/**
47+
* @param {Array<string>} files
48+
* @param {Config[]} cs
49+
* @return {Config[]}
50+
*/
51+
function configSetFiles (files, cs) {
52+
for (const c of cs) {
53+
c.files = files
54+
}
55+
return cs
56+
}
57+
58+
/**
59+
* @type {Config[]}
60+
* @see https://eslint.org/
4561
*/
4662
export default [
4763
{
4864
name: 'general',
4965
plugins: {
50-
'import': plugin_import,
66+
import: plugin_import,
5167
'simple-import-sort': plugin_simpleImportSort,
5268
'license-header': plugin_header,
53-
'n': plugin_n,
69+
n: plugin_n,
5470
},
5571
rules: {
5672
'n/prefer-node-protocol': 'error',
5773
'sort-imports': 'off',
5874
'import/order': [
5975
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
6076
'error', {
61-
'groups': [
77+
groups: [
6278
'builtin',
6379
'external',
6480
/* and then all the rest */
@@ -73,103 +89,101 @@ export default [
7389
'license-header/header': ['error', licenseHeaderFile],
7490
},
7591
},
92+
...configSetFiles(['**/*.{js,mjs,cjs}'], [
93+
...config_neostandard({ noJsx: true, ts: false }),
94+
{
95+
...plugin_jsdoc.configs['flat/recommended'],
96+
},
97+
{
98+
name: 'jsdoc-override',
99+
plugins: {
100+
jsdoc: plugin_jsdoc,
101+
},
102+
settings: {
103+
jsdoc: {
104+
mode: 'jsdoc',
105+
},
106+
},
107+
rules: {
108+
'jsdoc/no-undefined-types': 'error',
109+
'jsdoc/check-tag-names': 0,
110+
'jsdoc/check-types': 'error',
111+
'jsdoc/require-hyphen-before-param-description': ['error', 'always'],
112+
'jsdoc/require-jsdoc': 0,
113+
'jsdoc/require-param': 0,
114+
'jsdoc/require-param-description': 0,
115+
'jsdoc/require-param-name': 'error',
116+
'jsdoc/require-param-type': 'error',
117+
'jsdoc/require-property': 0,
118+
'jsdoc/require-property-description': 0,
119+
'jsdoc/require-property-name': 'error',
120+
'jsdoc/require-property-type': 'error',
121+
'jsdoc/require-returns': 0,
122+
'jsdoc/require-returns-check': 'error',
123+
'jsdoc/require-returns-description': 0,
124+
'jsdoc/require-returns-type': 'error',
125+
'jsdoc/require-throws': 'error',
126+
'jsdoc/require-yields': 0,
127+
'jsdoc/require-yields-check': 'error',
128+
'jsdoc/sort-tags': 'warn',
129+
}
130+
},
131+
]),
76132
{
77133
files: ['**/*.{js,cjs}'],
78134
rules: {
79135
'simple-import-sort/imports': 'off',
80136
'import/order': [
81137
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
82138
'error', {
83-
'groups': [
139+
groups: [
84140
'builtin',
85141
'external',
86142
/* and then all the rest */
87143
],
88-
'alphabetize': { order: "asc" },
89-
'named': true,
144+
alphabetize: { order: 'asc' },
145+
named: true,
90146
'newlines-between': 'always',
91147
}],
92148
}
93149
},
94-
{
95-
files: ['**/*.{js,mjs,cjs}'],
96-
rules: plugin_js.configs.recommended.rules,
97-
},
98-
{
99-
...plugin_jsdoc.configs['flat/recommended'],
100-
files: ['**/*.{js,mjs,cjs}'],
101-
},
102-
{
103-
name: 'jsdoc-override',
104-
files: ['**/*.{js,mjs,cjs}'],
105-
plugins: {
106-
'jsdoc': plugin_jsdoc,
150+
...configSetFiles(['**/*.ts'], [
151+
{
152+
...config_love,
107153
},
108-
settings: {
109-
jsdoc: {
110-
mode: 'jsdoc',
154+
{
155+
plugins: {
156+
tsdoc: plugin_tsdoc,
111157
},
112-
},
113-
rules: {
114-
'jsdoc/no-undefined-types': 'error',
115-
'jsdoc/check-tag-names': 0,
116-
'jsdoc/check-types': 'error',
117-
'jsdoc/require-hyphen-before-param-description': ['error', 'always'],
118-
'jsdoc/require-jsdoc': 0,
119-
'jsdoc/require-param': 0,
120-
'jsdoc/require-param-description': 0,
121-
'jsdoc/require-param-name': 'error',
122-
'jsdoc/require-param-type': 'error',
123-
'jsdoc/require-property': 0,
124-
'jsdoc/require-property-description': 0,
125-
'jsdoc/require-property-name': 'error',
126-
'jsdoc/require-property-type': 'error',
127-
'jsdoc/require-returns': 0,
128-
'jsdoc/require-returns-check': 'error',
129-
'jsdoc/require-returns-description': 0,
130-
'jsdoc/require-returns-type': 'error',
131-
'jsdoc/require-throws': 'error',
132-
'jsdoc/require-yields': 0,
133-
'jsdoc/require-yields-check': 'error',
134-
'jsdoc/sort-tags': 'warn',
135-
}
136-
},
137-
{
138-
...config_love,
139-
files: ['**/*.ts']
140-
},
141-
{
142-
files: ['**/*.ts'],
143-
plugins: {
144-
'tsdoc': plugin_tsdoc,
145-
},
146-
languageOptions: {
147-
parserOptions: {
148-
// override
149-
project: false,
158+
languageOptions: {
159+
parserOptions: {
160+
// override
161+
project: false,
162+
},
163+
},
164+
rules: {
165+
'@typescript-eslint/consistent-type-imports': ['error', {
166+
fixStyle: 'separate-type-imports',
167+
}],
168+
'@typescript-eslint/unbound-method': ['error', {
169+
ignoreStatic: true,
170+
}],
171+
'class-methods-use-this': 'off',
172+
'@typescript-eslint/class-methods-use-this': 'off',
173+
'@typescript-eslint/no-redundant-type-constituents': 'off',
174+
'@typescript-eslint/no-magic-numbers': 'off',
175+
'@typescript-eslint/no-explicit-any': 'off',
176+
'@typescript-eslint/prefer-destructuring': 'off',
177+
'tsdoc/syntax': 'error',
150178
},
151179
},
152-
rules: {
153-
'@typescript-eslint/consistent-type-imports': ['error', {
154-
fixStyle: 'separate-type-imports',
155-
}],
156-
'@typescript-eslint/unbound-method': ['error', {
157-
ignoreStatic: true,
158-
}],
159-
'class-methods-use-this': 'off',
160-
'@typescript-eslint/class-methods-use-this': 'off',
161-
'@typescript-eslint/no-redundant-type-constituents': 'off',
162-
'@typescript-eslint/no-magic-numbers': 'off',
163-
'@typescript-eslint/no-explicit-any': 'off',
164-
'@typescript-eslint/prefer-destructuring': 'off',
165-
'tsdoc/syntax': 'error',
166-
},
167-
},
180+
]),
168181
{
169182
files: [
170183
'**/eslint.config.{js,mjs,cjs}',
171184
'**/webpack.config.js',
172-
'**/.mocharc.js'
185+
'**/.mocharc.js',
186+
'**/.jest.config.js'
173187
],
174188
languageOptions: {
175189
globals: globals.node

tools/code-style/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"eslint-plugin-simple-import-sort": "12.1.1",
1818
"eslint-plugin-tsdoc": "0.4.0",
1919
"globals": "^16.0.0",
20+
"neostandard": "0.12.1",
2021
"typescript-eslint": "8.27.0"
2122
},
2223
"scripts": {

0 commit comments

Comments
 (0)