Skip to content

Commit

Permalink
Support ESLint 9 and Node.js 18+
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse Parsons <jeparson@microsoft.com>
  • Loading branch information
mkacmar and JesseParsons committed Sep 29, 2024
1 parent 3a9984f commit d55346f
Show file tree
Hide file tree
Showing 17 changed files with 3,601 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node-version-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 22
- run: npm i
- run: npm test

Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
node-version: 22
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm publish
Expand Down
11 changes: 6 additions & 5 deletions lib/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ module.exports = {
},
hasFullTypeInformation(context) {
var hasFullTypeInformation = (
context &&
this.isTypeScriptParserServices(context.parserServices) &&
context.parserServices.hasFullTypeInformation === true
context &&
context.sourceCode &&
context.sourceCode.parserServices &&
this.isTypeScriptParserServices(context.sourceCode.parserServices)
);
return hasFullTypeInformation;
},
getFullTypeChecker(context) {
return this.hasFullTypeInformation(context) ? context.parserServices.program.getTypeChecker() : null;
return this.hasFullTypeInformation(context) ? context.sourceCode.parserServices.program.getTypeChecker() : null;
},
getNodeTypeAsString(fullTypeChecker, node, context) {
if (fullTypeChecker && node) {
const tsNode = context.parserServices.esTreeNodeToTSNodeMap.get(node);
const tsNode = context.sourceCode.parserServices.esTreeNodeToTSNodeMap.get(node);
const tsType = fullTypeChecker.getTypeAtLocation(tsNode);
const type = fullTypeChecker.typeToString(tsType);
return type;
Expand Down
7 changes: 3 additions & 4 deletions lib/rules/no-insecure-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ module.exports = {
}

function shouldFix( varExceptions,context, node) {
let sourceCode = context.getSourceCode();
// check variable for unfixable pattern e.g. `var insecureURL = "http://..."`
let text = node.parent
? sourceCode.getText(node.parent)
: sourceCode.getText(node);
? context.sourceCode.getText(node.parent)
: context.sourceCode.getText(node);
// if no match, fix the line
return !matches(varExceptions,text);
}
Expand Down Expand Up @@ -123,7 +122,7 @@ module.exports = {
fix(fixer) {
// Only fix if it contains an http url
if (node.value.raw.toLowerCase().includes("http")) {
let escapedString = JSON.stringify(context.getSourceCode().getText(node));
let escapedString = JSON.stringify(context.sourceCode.getText(node));
// delete "" that JSON.stringify created and convert to `` string
escapedString = ``+ escapedString.substring(1, escapedString.length-1);
let fixedString = escapedString.replace(/http:/i, "https:");
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-postmessage-star-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {

// Check that object type is Window when full type information is available
if (fullTypeChecker) {
const tsNode = context.parserServices.esTreeNodeToTSNodeMap.get(node.callee.object);
const tsNode = context.sourceCode.parserServices.esTreeNodeToTSNodeMap.get(node.callee.object);
const tsType = fullTypeChecker.getTypeAtLocation(tsNode);
const type = fullTypeChecker.typeToString(tsType);
if (type !== "any" && type !== "Window") {
Expand Down
Loading

0 comments on commit d55346f

Please # to comment.