Skip to content

Commit 4eefb35

Browse files
markusnisslMarkus.Nissl
and
Markus.Nissl
authored
fix(plugin-eslint): eslint startline can be zero (#563)
In case tsconfig does not contain correct setup, e.g., "strictNullChecks": true, eslint throws warnings for line "zero". The current schema does not show the warning, it just throws an internal error. This fix allows for warning on line zero to be collected for the report. Fixes issues such as: ``` { "code": "too_small", "minimum": 0, "type": "number", "inclusive": false, "exact": false, "message": "Number must be greater than 0", "path": [ 117, "details", "issues", 3, "source", "position", "startLine" ] }, ``` for issues like `0:1 warning This rule requires the `strictNullChecks` compiler option to be turned on to function correctly @typescript-eslint/prefer-nullish-coalescing` --------- Co-authored-by: Markus.Nissl <[email protected]>
1 parent d431d3f commit 4eefb35

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

packages/plugin-eslint/src/lib/meta/groups.ts

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export function groupsFromRuleCategories(rules: RuleData[]): Group[] {
5656
const categoriesMap = rules.reduce<Record<string, Record<string, string[]>>>(
5757
(acc, { meta: { docs }, ruleId, options }) => {
5858
// meta.docs.category still used by some popular plugins (e.g. import, react, functional)
59-
// eslint-disable-next-line deprecation/deprecation
6059
const category = docs?.category;
6160
if (!category) {
6261
return acc;

packages/plugin-eslint/src/lib/runner/transform.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ function convertIssue(issue: LintIssue): Issue {
6565
severity: convertSeverity(issue.severity),
6666
source: {
6767
file: issue.filePath,
68-
position: {
69-
startLine: issue.line,
70-
...(issue.column > 0 && { startColumn: issue.column }),
71-
...(issue.endLine &&
72-
issue.endLine > 0 && {
73-
endLine: issue.endLine,
74-
}),
75-
...(issue.endColumn &&
76-
issue.endColumn > 0 && { endColumn: issue.endColumn }),
77-
},
68+
...(issue.line > 0 && {
69+
position: {
70+
startLine: issue.line,
71+
...(issue.column > 0 && { startColumn: issue.column }),
72+
...(issue.endLine &&
73+
issue.endLine > 0 && {
74+
endLine: issue.endLine,
75+
}),
76+
...(issue.endColumn &&
77+
issue.endColumn > 0 && { endColumn: issue.endColumn }),
78+
},
79+
}),
7880
},
7981
};
8082
}

packages/plugin-eslint/src/lib/runner/transform.unit.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ describe('lintResultsToAudits', () => {
7272
},
7373
],
7474
},
75+
{
76+
filePath: 'src/app/test/strictNullChecks.ts',
77+
messages: [
78+
{
79+
ruleId: '@typescript-eslint/prefer-nullish-coalescing',
80+
message:
81+
'This rule requires the strictNullChecks compiler option to be turned on to function correctly',
82+
severity: 1,
83+
line: 0,
84+
column: 1,
85+
},
86+
],
87+
},
7588
{
7689
filePath: 'src/app/pages/settings.component.ts',
7790
messages: [
@@ -90,21 +103,25 @@ describe('lintResultsToAudits', () => {
90103
'src/app/app.component.ts': {
91104
'max-lines': [500],
92105
'@typescript-eslint/no-explicit-any': [],
106+
'@typescript-eslint/prefer-nullish-coalescing': [],
93107
'unicorn/no-abusive-eslint-disable': [],
94108
},
95109
'src/app/pages/settings.component.ts': {
96110
'max-lines': [500],
97111
'@typescript-eslint/no-explicit-any': [],
112+
'@typescript-eslint/prefer-nullish-coalescing': [],
98113
'unicorn/no-abusive-eslint-disable': [],
99114
},
100115
'src/app/graphql/generated.ts': {
101116
'max-lines': [500],
102117
'@typescript-eslint/no-explicit-any': [],
118+
'@typescript-eslint/prefer-nullish-coalescing': [],
103119
'unicorn/no-abusive-eslint-disable': [],
104120
},
105121
'src/app/app.component.spec.ts': {
106122
'max-lines': [800],
107123
'@typescript-eslint/no-explicit-any': [],
124+
'@typescript-eslint/prefer-nullish-coalescing': [],
108125
'unicorn/no-abusive-eslint-disable': [],
109126
},
110127
},
@@ -221,6 +238,24 @@ describe('lintResultsToAudits', () => {
221238
],
222239
},
223240
},
241+
{
242+
slug: 'typescript-eslint-prefer-nullish-coalescing',
243+
score: 0,
244+
value: 1,
245+
displayValue: '1 warning',
246+
details: {
247+
issues: [
248+
{
249+
message:
250+
'This rule requires the strictNullChecks compiler option to be turned on to function correctly',
251+
severity: 'warning',
252+
source: {
253+
file: 'src/app/test/strictNullChecks.ts',
254+
},
255+
},
256+
],
257+
},
258+
},
224259
]);
225260
});
226261
});

0 commit comments

Comments
 (0)