Skip to content

Commit

Permalink
Add missing null nodeTypes
Browse files Browse the repository at this point in the history
`LintMessage.nodeType` is currently defined as required but nullable.
Actual implementation explicitly sets it to `null` in a couple places
and omits it in several.

After discussion in eslint#16968, we initially leaned toward making it
non-nullable but optional. I pursued that, but it resulted in slightly
more runtime code changes, including some branching to set it
conditionally.

Instead, I'm presenting the opposite solution of updating the remaining
implementations to match the existing type definition by explicitly
setting `nodeType` to `null`.
  • Loading branch information
btmills committed Apr 9, 2023
1 parent d13ff1d commit 848050e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/cli-engine/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ function createIgnoreResult(filePath, baseDir) {
severity: 1,
message,
line: 0,
column: 0
column: 0,
nodeType: null
}
],
suppressedMessages: [],
Expand Down
3 changes: 2 additions & 1 deletion lib/eslint/eslint-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ function createIgnoreResult(filePath, baseDir) {
severity: 1,
message,
line: 0,
column: 0
column: 0,
nodeType: null
}
],
suppressedMessages: [],
Expand Down
3 changes: 2 additions & 1 deletion lib/linter/config-comment-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ module.exports = class ConfigCommentParser {
severity: 2,
message: `Failed to parse JSON from '${normalizedString}': ${ex.message}`,
line: location.start.line,
column: location.start.column + 1
column: location.start.column + 1,
nodeType: null
}
};

Expand Down
15 changes: 10 additions & 5 deletions lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ function parse(text, languageOptions, filePath) {
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
column: ex.column,
nodeType: null
}
};
}
Expand Down Expand Up @@ -1281,7 +1282,8 @@ class Linter {
severity: 2,
message: `Configured parser '${config.parser}' was not found.`,
line: 0,
column: 0
column: 0,
nodeType: null
}];
}
parserName = config.parser;
Expand Down Expand Up @@ -1492,7 +1494,8 @@ class Linter {
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
column: ex.column,
nodeType: null
}
];
}
Expand Down Expand Up @@ -1757,7 +1760,8 @@ class Linter {
severity: 1,
message: `No matching configuration found for ${filename}.`,
line: 0,
column: 0
column: 0,
nodeType: null
}
];
}
Expand Down Expand Up @@ -1822,7 +1826,8 @@ class Linter {
severity: 2,
message,
line: ex.lineNumber,
column: ex.column
column: ex.column,
nodeType: null
}
];
}
Expand Down

0 comments on commit 848050e

Please sign in to comment.