Skip to content

Commit 567b9e6

Browse files
johns70JoshMock
andauthored
chore: migrate to neostandard #2920 (#3201)
Co-authored-by: Josh Mock <joshua.mock@elastic.co> Co-authored-by: Josh Mock <josh@joshmock.com>
1 parent 4d3c7db commit 567b9e6

104 files changed

Lines changed: 256 additions & 597 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.mjs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
// we import the base configuration from Neostandard (a modern ESLint preset)
7+
// and also its internal plugins
8+
import neostandard, { plugins } from 'neostandard'
9+
import { defineConfig } from 'eslint/config'
10+
11+
// we export the ESLint configuration
12+
export default defineConfig([
13+
...neostandard({
14+
// enable support for TypeScript
15+
ts: true,
16+
// external dependencies (never lint them)
17+
ignores: [
18+
'node_modules/**',
19+
// generated code (CommonJS build) It regenerates automatically, linting makes no sense
20+
'lib/**',
21+
// generated code (ESM build) Same as lib, it is overwritten in each build
22+
'esm/**',
23+
// coverage reports (not source code)
24+
'coverage/**'
25+
]
26+
}),
27+
28+
// style rules applied to the important project files
29+
// applies to:
30+
// src: source code
31+
// test: tests
32+
// scripts: internal tools
33+
{
34+
files: ['src/**/*.js', 'src/**/*.ts', 'test/**/*.js', 'test/**/*.ts', 'scripts/**/*.js'],
35+
plugins: {
36+
// plugin that controls formatting (indentation, spaces, and other syntax rules)
37+
'@stylistic': plugins['@stylistic']
38+
},
39+
rules: {
40+
// requires a space after comments
41+
'@stylistic/spaced-comment': ['error', 'always', {
42+
// allows exceptions like //#region
43+
exceptions: ['#', '/'],
44+
markers: ['/']
45+
}],
46+
// prohibits the use of semicolon ;
47+
'@stylistic/semi': ['error', 'never'],
48+
// force 2-space indentation
49+
'@stylistic/indent': ['error', 2],
50+
// forces a new line or line break at the end of the file
51+
'@stylistic/eol-last': ['error', 'always'],
52+
// requires space before parentheses in functions () {}
53+
'@stylistic/space-before-function-paren': ['error', 'always'],
54+
// disables the requirement for lines between class methods
55+
'@stylistic/lines-between-class-members': 'off'
56+
}
57+
},
58+
59+
// relaxed rules for code generated inside src
60+
{
61+
files: ['src/**/*.ts'],
62+
// this is code generated as an API client
63+
rules: {
64+
// snake_case
65+
camelcase: 'off',
66+
// generator uses void expressions
67+
'no-void': 'off',
68+
// the generated regexes may seem incorrect but they are not
69+
'no-useless-escape': 'off',
70+
// the generated code can use let even though it could be const, to be more permissive
71+
'prefer-const': 'off',
72+
// side effects in some expressions
73+
'no-unused-expressions': 'off',
74+
// allows use of comma operator in generated code
75+
'no-sequences': 'off',
76+
// variables can exist even if they are not being used
77+
'no-unused-vars': 'off',
78+
// variables in TS that are not being used
79+
'@typescript-eslint/no-unused-vars': 'off',
80+
// allows automatically generated lowercase constructors
81+
'new-cap': 'off'
82+
}
83+
},
84+
85+
// ci .buildkite, scripts exceptions
86+
{
87+
files: ['.buildkite/**/*.mjs'],
88+
rules: {
89+
// scripts can have unused variables (args)
90+
'no-unused-vars': 'off',
91+
// regex in scripts may require special escapes
92+
'no-useless-escape': 'off'
93+
}
94+
},
95+
96+
// rules for the tests
97+
{
98+
files: ['test/**/*.js', 'test/**/*.ts', 'test/**/*.mjs'],
99+
rules: {
100+
// tests may use snake_case data
101+
camelcase: 'off',
102+
// tests often declare unused helpers
103+
'no-unused-vars': 'off',
104+
// tests often declare unused helpers or variable of ts
105+
'@typescript-eslint/no-unused-vars': 'off',
106+
// regex in tests may seem unnecessary
107+
'no-useless-escape': 'off'
108+
}
109+
}
110+
])

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"test:coverage-ui": "npm run build && tap --coverage --coverage-report=html",
3636
"test:integration-build": "npm run build && node test/integration/index.js",
3737
"test:integration": "npm run test:integration-build && env tap run --jobs=1 --reporter=junit --reporter-file=report-junit.xml generated-tests/",
38-
"lint": "ts-standard src",
39-
"lint:fix": "ts-standard --fix src",
38+
"lint": "eslint",
39+
"lint:fix": "eslint . --fix ",
4040
"license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'",
4141
"license-header": "./scripts/check-spdx",
4242
"generate-version": "node scripts/generate-version.js",
@@ -90,11 +90,13 @@
9090
"c8": "10.1.3",
9191
"cross-zip": "4.0.1",
9292
"desm": "1.3.1",
93+
"eslint": "^9.39.3",
9394
"inly": "5.0.1",
9495
"js-yaml": "4.1.1",
9596
"license-checker": "25.0.1",
9697
"minimist": "1.2.8",
9798
"ms": "2.1.3",
99+
"neostandard": "^0.13.0",
98100
"node-abort-controller": "3.1.1",
99101
"ora": "9.0.0",
100102
"proxy": "2.2.0",
@@ -104,7 +106,6 @@
104106
"stoppable": "1.1.0",
105107
"tap": "21.5.0",
106108
"ts-node": "10.9.2",
107-
"ts-standard": "12.0.2",
108109
"tsc-esm-fix": "3.1.2",
109110
"typescript": "5.9.3",
110111
"workq": "3.0.0",

scripts/fix-esm-require.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21
/*
32
* Copyright Elasticsearch B.V. and contributors
43
* SPDX-License-Identifier: Apache-2.0
@@ -16,8 +15,8 @@ if (fs.existsSync(clientPath)) {
1615
let content = fs.readFileSync(clientPath, 'utf8')
1716

1817
// Check if we need to add createRequire
19-
const hasPackageRequire = content.includes("require('../package.json')") ||
20-
content.includes("require('@elastic/transport/package.json')")
18+
const hasPackageRequire = content.includes('require(\'../package.json\')') ||
19+
content.includes('require(\'@elastic/transport/package.json\')')
2120

2221
if (!content.includes('createRequire') && hasPackageRequire) {
2322
// Find the last import statement
@@ -28,7 +27,7 @@ if (fs.existsSync(clientPath)) {
2827
const beforeImport = content.substring(0, newlineAfterImport + 1)
2928
const afterImport = content.substring(newlineAfterImport + 1)
3029

31-
content = beforeImport + "import { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n" + afterImport
30+
content = beforeImport + 'import { createRequire } from \'node:module\';\nconst require = createRequire(import.meta.url);\n' + afterImport
3231
}
3332

3433
fs.writeFileSync(clientPath, content, 'utf8')
@@ -43,8 +42,8 @@ if (fs.existsSync(helpersPath)) {
4342
let content = fs.readFileSync(helpersPath, 'utf8')
4443

4544
// Fix the apache-arrow import that tsc-esm-fix incorrectly modified
46-
const originalApacheImport = "import { tableFromIPC, AsyncRecordBatchStreamReader } from 'apache-arrow/Arrow.node.js';"
47-
const fixedApacheImport = "import { tableFromIPC, AsyncRecordBatchStreamReader } from 'apache-arrow/Arrow.node';"
45+
const originalApacheImport = 'import { tableFromIPC, AsyncRecordBatchStreamReader } from \'apache-arrow/Arrow.node.js\';'
46+
const fixedApacheImport = 'import { tableFromIPC, AsyncRecordBatchStreamReader } from \'apache-arrow/Arrow.node\';'
4847

4948
if (content.includes(originalApacheImport)) {
5049
content = content.replace(originalApacheImport, fixedApacheImport)

scripts/generate-version.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21
/*
32
* Copyright Elasticsearch B.V. and contributors
43
* SPDX-License-Identifier: Apache-2.0
@@ -31,4 +30,4 @@ export const transportVersion: string = '${transportVersion}'
3130
`
3231

3332
fs.writeFileSync(outPath, content, 'utf8')
34-
console.log(`Generated ${outPath} (client: ${clientPkg.version}, transport: ${transportVersion})`)
33+
console.log(`Generated ${outPath} (client: ${clientPkg.version}, transport: ${transportVersion})`)

src/api/api/async_search.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable import/export */
7-
/* eslint-disable @typescript-eslint/no-misused-new */
8-
/* eslint-disable @typescript-eslint/no-extraneous-class */
9-
/* eslint-disable @typescript-eslint/no-unused-vars */
10-
116
// This file was automatically generated by elastic/elastic-client-generator-js
127
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
138
// and elastic/elastic-client-generator-js to regenerate this file again.
@@ -334,7 +329,7 @@ export default class AsyncSearch {
334329
for (const key in params) {
335330
if (acceptedBody.includes(key)) {
336331
body = body ?? {}
337-
if (key === 'sort' && typeof params[key] === 'string' && params[key].includes(':')) { // eslint-disable-line
332+
if (key === 'sort' && typeof params[key] === 'string' && params[key].includes(':')) {
338333
querystring[key] = params[key]
339334
} else {
340335
// @ts-expect-error

src/api/api/autoscaling.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable import/export */
7-
/* eslint-disable @typescript-eslint/no-misused-new */
8-
/* eslint-disable @typescript-eslint/no-extraneous-class */
9-
/* eslint-disable @typescript-eslint/no-unused-vars */
10-
116
// This file was automatically generated by elastic/elastic-client-generator-js
127
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
138
// and elastic/elastic-client-generator-js to regenerate this file again.

src/api/api/bulk.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable import/export */
7-
/* eslint-disable @typescript-eslint/no-misused-new */
8-
/* eslint-disable @typescript-eslint/no-extraneous-class */
9-
/* eslint-disable @typescript-eslint/no-unused-vars */
10-
116
// This file was automatically generated by elastic/elastic-client-generator-js
127
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
138
// and elastic/elastic-client-generator-js to regenerate this file again.

src/api/api/capabilities.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable import/export */
7-
/* eslint-disable @typescript-eslint/no-misused-new */
8-
/* eslint-disable @typescript-eslint/no-extraneous-class */
9-
/* eslint-disable @typescript-eslint/no-unused-vars */
10-
116
// This file was automatically generated by elastic/elastic-client-generator-js
127
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
138
// and elastic/elastic-client-generator-js to regenerate this file again.

src/api/api/cat.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable import/export */
7-
/* eslint-disable @typescript-eslint/no-misused-new */
8-
/* eslint-disable @typescript-eslint/no-extraneous-class */
9-
/* eslint-disable @typescript-eslint/no-unused-vars */
10-
116
// This file was automatically generated by elastic/elastic-client-generator-js
127
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
138
// and elastic/elastic-client-generator-js to regenerate this file again.

src/api/api/ccr.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable import/export */
7-
/* eslint-disable @typescript-eslint/no-misused-new */
8-
/* eslint-disable @typescript-eslint/no-extraneous-class */
9-
/* eslint-disable @typescript-eslint/no-unused-vars */
10-
116
// This file was automatically generated by elastic/elastic-client-generator-js
127
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
138
// and elastic/elastic-client-generator-js to regenerate this file again.

0 commit comments

Comments
 (0)