Skip to content

Commit

Permalink
fix(plugin-eslint): eslint startline can be zero (#563)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
markusnissl and Markus.Nissl authored Mar 18, 2024
1 parent d431d3f commit 4eefb35
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/plugin-eslint/src/lib/meta/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export function groupsFromRuleCategories(rules: RuleData[]): Group[] {
const categoriesMap = rules.reduce<Record<string, Record<string, string[]>>>(
(acc, { meta: { docs }, ruleId, options }) => {
// meta.docs.category still used by some popular plugins (e.g. import, react, functional)
// eslint-disable-next-line deprecation/deprecation
const category = docs?.category;
if (!category) {
return acc;
Expand Down
22 changes: 12 additions & 10 deletions packages/plugin-eslint/src/lib/runner/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ function convertIssue(issue: LintIssue): Issue {
severity: convertSeverity(issue.severity),
source: {
file: issue.filePath,
position: {
startLine: issue.line,
...(issue.column > 0 && { startColumn: issue.column }),
...(issue.endLine &&
issue.endLine > 0 && {
endLine: issue.endLine,
}),
...(issue.endColumn &&
issue.endColumn > 0 && { endColumn: issue.endColumn }),
},
...(issue.line > 0 && {
position: {
startLine: issue.line,
...(issue.column > 0 && { startColumn: issue.column }),
...(issue.endLine &&
issue.endLine > 0 && {
endLine: issue.endLine,
}),
...(issue.endColumn &&
issue.endColumn > 0 && { endColumn: issue.endColumn }),
},
}),
},
};
}
Expand Down
35 changes: 35 additions & 0 deletions packages/plugin-eslint/src/lib/runner/transform.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ describe('lintResultsToAudits', () => {
},
],
},
{
filePath: 'src/app/test/strictNullChecks.ts',
messages: [
{
ruleId: '@typescript-eslint/prefer-nullish-coalescing',
message:
'This rule requires the strictNullChecks compiler option to be turned on to function correctly',
severity: 1,
line: 0,
column: 1,
},
],
},
{
filePath: 'src/app/pages/settings.component.ts',
messages: [
Expand All @@ -90,21 +103,25 @@ describe('lintResultsToAudits', () => {
'src/app/app.component.ts': {
'max-lines': [500],
'@typescript-eslint/no-explicit-any': [],
'@typescript-eslint/prefer-nullish-coalescing': [],
'unicorn/no-abusive-eslint-disable': [],
},
'src/app/pages/settings.component.ts': {
'max-lines': [500],
'@typescript-eslint/no-explicit-any': [],
'@typescript-eslint/prefer-nullish-coalescing': [],
'unicorn/no-abusive-eslint-disable': [],
},
'src/app/graphql/generated.ts': {
'max-lines': [500],
'@typescript-eslint/no-explicit-any': [],
'@typescript-eslint/prefer-nullish-coalescing': [],
'unicorn/no-abusive-eslint-disable': [],
},
'src/app/app.component.spec.ts': {
'max-lines': [800],
'@typescript-eslint/no-explicit-any': [],
'@typescript-eslint/prefer-nullish-coalescing': [],
'unicorn/no-abusive-eslint-disable': [],
},
},
Expand Down Expand Up @@ -221,6 +238,24 @@ describe('lintResultsToAudits', () => {
],
},
},
{
slug: 'typescript-eslint-prefer-nullish-coalescing',
score: 0,
value: 1,
displayValue: '1 warning',
details: {
issues: [
{
message:
'This rule requires the strictNullChecks compiler option to be turned on to function correctly',
severity: 'warning',
source: {
file: 'src/app/test/strictNullChecks.ts',
},
},
],
},
},
]);
});
});

0 comments on commit 4eefb35

Please sign in to comment.