Skip to content

Commit eed2d2d

Browse files
committed
Modernize ESLint configuration
1 parent 393efa3 commit eed2d2d

8 files changed

Lines changed: 86 additions & 121 deletions

File tree

.eslintrc.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

__tests__/report/get-report.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ describe('getBadge', () => {
88
badgeTitle: 'tests'
99
}
1010
const badge = getBadge(5, 0, 1, options)
11-
expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/tests-5%20passed%2C%201%20skipped-success)')
11+
expect(badge).toBe(
12+
'![Tests passed successfully](https://img.shields.io/badge/tests-5%20passed%2C%201%20skipped-success)'
13+
)
1214
})
1315

1416
it('handles badge title with single hyphen', () => {
@@ -28,7 +30,9 @@ describe('getBadge', () => {
2830
}
2931
const badge = getBadge(10, 0, 0, options)
3032
// All hyphens in the title should be encoded as --
31-
expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/integration--api--tests-10%20passed-success)')
33+
expect(badge).toBe(
34+
'![Tests passed successfully](https://img.shields.io/badge/integration--api--tests-10%20passed-success)'
35+
)
3236
})
3337

3438
it('handles badge title with multiple underscores', () => {
@@ -38,7 +42,9 @@ describe('getBadge', () => {
3842
}
3943
const badge = getBadge(10, 0, 0, options)
4044
// All underscores in the title should be encoded as __
41-
expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/my__integration__test-10%20passed-success)')
45+
expect(badge).toBe(
46+
'![Tests passed successfully](https://img.shields.io/badge/my__integration__test-10%20passed-success)'
47+
)
4248
})
4349

4450
it('handles badge title with version format containing hyphen', () => {
@@ -48,7 +54,9 @@ describe('getBadge', () => {
4854
}
4955
const badge = getBadge(1, 0, 0, options)
5056
// The hyphen in "12.0-ubi" should be encoded as --
51-
expect(badge).toBe('![Tests passed successfully](https://img.shields.io/badge/MariaDb%2012.0--ubi%20database%20tests-1%20passed-success)')
57+
expect(badge).toBe(
58+
'![Tests passed successfully](https://img.shields.io/badge/MariaDb%2012.0--ubi%20database%20tests-1%20passed-success)'
59+
)
5260
})
5361

5462
it('handles badge title with dots and hyphens', () => {
@@ -57,7 +65,9 @@ describe('getBadge', () => {
5765
badgeTitle: 'v1.2.3-beta-test'
5866
}
5967
const badge = getBadge(4, 1, 0, options)
60-
expect(badge).toBe('![Tests failed](https://img.shields.io/badge/v1.2.3--beta--test-4%20passed%2C%201%20failed-critical)')
68+
expect(badge).toBe(
69+
'![Tests failed](https://img.shields.io/badge/v1.2.3--beta--test-4%20passed%2C%201%20failed-critical)'
70+
)
6171
})
6272

6373
it('preserves structural hyphens between label and message', () => {
@@ -67,7 +77,9 @@ describe('getBadge', () => {
6777
}
6878
const badge = getBadge(2, 3, 1, options)
6979
// The URI should have literal hyphens separating title-message-color
70-
expect(badge).toBe('![Tests failed](https://img.shields.io/badge/test--suite-2%20passed%2C%203%20failed%2C%201%20skipped-critical)')
80+
expect(badge).toBe(
81+
'![Tests failed](https://img.shields.io/badge/test--suite-2%20passed%2C%203%20failed%2C%201%20skipped-critical)'
82+
)
7183
})
7284
})
7385

@@ -107,7 +119,9 @@ describe('getBadge', () => {
107119
it('includes passed, failed and skipped counts', () => {
108120
const options: ReportOptions = {...DEFAULT_OPTIONS}
109121
const badge = getBadge(5, 2, 1, options)
110-
expect(badge).toBe('![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%202%20failed%2C%201%20skipped-critical)')
122+
expect(badge).toBe(
123+
'![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%202%20failed%2C%201%20skipped-critical)'
124+
)
111125
})
112126

113127
it('uses "none" message when no tests', () => {
@@ -117,4 +131,3 @@ describe('getBadge', () => {
117131
})
118132
})
119133
})
120-

eslint.config.mjs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,58 @@ import jest from 'eslint-plugin-jest'
44
export default [
55
github.getFlatConfigs().recommended,
66
...github.getFlatConfigs().typescript,
7+
{
8+
settings: {
9+
'import/parsers': {
10+
'@typescript-eslint/parser': ['.ts', '.tsx']
11+
},
12+
'import/resolver': {
13+
typescript: {
14+
project: './tsconfig.json',
15+
alwaysTryTypes: true
16+
},
17+
node: {
18+
extensions: ['.js', '.mjs', '.ts', '.tsx']
19+
}
20+
}
21+
}
22+
},
723
{
824
files: ['src/**/*.ts'],
925
rules: {
10-
'no-shadow': 'off',
11-
'import/no-namespace': 'off',
1226
'i18n-text/no-en': 'off',
27+
'eslint-comments/no-use': 'off',
28+
'import/no-namespace': 'off',
29+
'import/no-named-as-default': 'off',
30+
'no-shadow': 'off',
31+
'no-unused-vars': 'off',
1332
'prefer-template': 'off',
14-
"@typescript-eslint/array-type": ['error', {default: 'array'}],
33+
camelcase: 'off',
34+
semi: 'off',
35+
'@typescript-eslint/array-type': ['error', {default: 'array'}],
1536
'@typescript-eslint/no-unused-vars': ['error', {varsIgnorePattern: '^_'}],
1637
'@typescript-eslint/no-shadow': ['error'],
17-
},
38+
// Modern replacements for deprecated rules from the legacy config.
39+
'@typescript-eslint/no-empty-object-type': 'error',
40+
'@typescript-eslint/no-require-imports': 'error'
41+
}
1842
},
1943
{
2044
files: ['__tests__/**/*.test.ts'],
2145
...jest.configs['flat/recommended'],
2246
plugins: {
23-
jest,
47+
jest
2448
},
2549
languageOptions: {
26-
globals: jest.environments.globals.globals,
50+
globals: jest.environments.globals.globals
2751
},
2852
rules: {
2953
'i18n-text/no-en': 'off',
3054
'import/no-namespace': 'off',
31-
"@typescript-eslint/array-type": ['error', {default: 'array'}],
32-
},
55+
'@typescript-eslint/array-type': ['error', {default: 'array'}],
56+
'@typescript-eslint/no-explicit-any': 'off',
57+
'@typescript-eslint/explicit-function-return-type': 'off'
58+
}
3359
},
3460
{
3561
ignores: [
@@ -41,7 +67,7 @@ export default [
4167
'assets/**',
4268
'reports/**',
4369
'eslint.config.mjs',
44-
'jest.config.cjs',
45-
],
46-
},
70+
'jest.config.cjs'
71+
]
72+
}
4773
]

src/parsers/dotnet-trx/dotnet-trx-parser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ export class DotnetTrxParser implements TestParser {
6262
}
6363

6464
private getTestClasses(trx: TrxReport): TestClass[] {
65-
if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined ||
66-
!trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))) {
65+
if (
66+
trx.TestRun.TestDefinitions === undefined ||
67+
trx.TestRun.Results === undefined ||
68+
!trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))
69+
) {
6770
return []
6871
}
6972

@@ -81,7 +84,7 @@ export class DotnetTrxParser implements TestParser {
8184

8285
const testClasses: {[name: string]: TestClass} = {}
8386
for (const r of unitTestsResults) {
84-
const className = r.test.TestMethod[0].$.className ?? "Unclassified"
87+
const className = r.test.TestMethod[0].$.className ?? 'Unclassified'
8588
let tc = testClasses[className]
8689
if (tc === undefined) {
8790
tc = new TestClass(className)

src/parsers/golang-json/golang-json-parser.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { ParseOptions, TestParser } from '../../test-parser.js'
1+
import {ParseOptions, TestParser} from '../../test-parser.js'
22

3-
import { GoTestEvent } from './golang-json-types.js'
4-
import { getExceptionSource } from '../../utils/node-utils.js'
5-
import { getBasePath, normalizeFilePath } from '../../utils/path-utils.js'
3+
import {GoTestEvent} from './golang-json-types.js'
64

75
import {
86
TestExecutionResult,
@@ -16,21 +14,24 @@ import {
1614
export class GolangJsonParser implements TestParser {
1715
assumedWorkDir: string | undefined
1816

19-
constructor(readonly options: ParseOptions) { }
17+
constructor(readonly options: ParseOptions) {}
2018

2119
async parse(path: string, content: string): Promise<TestRunResult> {
2220
const events = await this.getGolangTestEvents(path, content)
2321
return this.getTestRunResult(path, events)
2422
}
2523

2624
private async getGolangTestEvents(path: string, content: string): Promise<GoTestEvent[]> {
27-
return content.trim().split('\n').map((line, index) => {
28-
try {
29-
return JSON.parse(line) as GoTestEvent
30-
} catch (e) {
31-
throw new Error(`Invalid JSON at ${path} line ${index + 1}\n\n${e}`)
32-
}
33-
})
25+
return content
26+
.trim()
27+
.split('\n')
28+
.map((line, index) => {
29+
try {
30+
return JSON.parse(line) as GoTestEvent
31+
} catch (e) {
32+
throw new Error(`Invalid JSON at ${path} line ${index + 1}\n\n${e}`)
33+
}
34+
})
3435
}
3536

3637
private getTestRunResult(path: string, events: GoTestEvent[]): TestRunResult {
@@ -63,9 +64,8 @@ export class GolangJsonParser implements TestParser {
6364
continue
6465
}
6566

66-
let groupName: string | null
67-
let rest: string[]
68-
[groupName, ...rest] = event.Test.split('/')
67+
const [first, ...rest] = event.Test.split('/')
68+
let groupName: string | null = first
6969
let testName = rest.join('/')
7070
if (!testName) {
7171
testName = groupName
@@ -80,9 +80,8 @@ export class GolangJsonParser implements TestParser {
8080

8181
const lastEvent = eventGroup.at(-1)!
8282

83-
const result: TestExecutionResult = lastEvent.Action === 'pass' ? 'success'
84-
: lastEvent.Action === 'skip' ? 'skipped'
85-
: 'failed'
83+
const result: TestExecutionResult =
84+
lastEvent.Action === 'pass' ? 'success' : lastEvent.Action === 'skip' ? 'skipped' : 'failed'
8685
if (lastEvent.Elapsed === undefined) {
8786
throw new Error('missing elapsed on final test event')
8887
}
@@ -94,7 +93,7 @@ export class GolangJsonParser implements TestParser {
9493
.filter(e => e.Action === 'output')
9594
.map(e => e.Output ?? '')
9695
// Go output prepends indentation to help group tests - remove it
97-
.map(o => o.replace(/^ /, ''))
96+
.map(o => o.replace(/^ {4}/, ''))
9897

9998
// First and last lines will be generic "test started" and "test finished" lines - remove them
10099
outputEvents.splice(0, 1)
@@ -103,7 +102,7 @@ export class GolangJsonParser implements TestParser {
103102
const details = outputEvents.join('')
104103
error = {
105104
message: details,
106-
details: details
105+
details
107106
}
108107
}
109108

src/parsers/golang-json/golang-json-types.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
export type GoTestAction = 'start'
2-
| 'run'
3-
| 'pause'
4-
| 'cont'
5-
| 'pass'
6-
| 'bench'
7-
| 'fail'
8-
| 'output'
9-
| 'skip'
1+
export type GoTestAction = 'start' | 'run' | 'pause' | 'cont' | 'pass' | 'bench' | 'fail' | 'output' | 'skip'
102

113
export type GoTestEvent = {
124
Time: string

src/parsers/phpunit-junit/phpunit-junit-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class PhpunitJunitParser implements TestParser {
130130
}
131131

132132
const failure = failures[0]
133-
const details = typeof failure === 'string' ? failure : failure._ ?? ''
133+
const details = typeof failure === 'string' ? failure : (failure._ ?? '')
134134

135135
// PHPUnit provides file path directly in testcase attributes
136136
let filePath: string | undefined

src/parsers/tester-junit/tester-junit-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class NetteTesterJunitParser implements TestParser {
199199

200200
const failure = failures[0]
201201
// For Nette Tester, details are in the message attribute, not as inner text
202-
const details = typeof failure === 'string' ? failure : failure._ ?? failure.$?.message ?? ''
202+
const details = typeof failure === 'string' ? failure : (failure._ ?? failure.$?.message ?? '')
203203

204204
// Try to extract file path and line from error details
205205
let errorFilePath: string | undefined

0 commit comments

Comments
 (0)