forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for ignoring sync methods from certain locations (#392
) Co-authored-by: Sebastian Good <[email protected]>
- Loading branch information
1 parent
4efe60f
commit 5544f20
Showing
18 changed files
with
543 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict" | ||
|
||
const ts = (() => { | ||
try { | ||
// eslint-disable-next-line n/no-unpublished-require | ||
return require("typescript") | ||
} catch { | ||
return null | ||
} | ||
})() | ||
|
||
/** | ||
* @param {import('typescript').Type | null} type | ||
* @returns {string | null} | ||
*/ | ||
module.exports = function getFullTypeName(type) { | ||
if (ts === null || type === null) { | ||
return null | ||
} | ||
|
||
/** | ||
* @type {string[]} | ||
*/ | ||
let nameParts = [] | ||
let currentSymbol = type.getSymbol() | ||
while (currentSymbol !== undefined) { | ||
if ( | ||
currentSymbol.valueDeclaration?.kind === ts.SyntaxKind.SourceFile || | ||
currentSymbol.valueDeclaration?.kind === | ||
ts.SyntaxKind.ModuleDeclaration | ||
) { | ||
break | ||
} | ||
|
||
nameParts.unshift(currentSymbol.getName()) | ||
currentSymbol = | ||
/** @type {import('typescript').Symbol & {parent: import('typescript').Symbol | undefined}} */ ( | ||
currentSymbol | ||
).parent | ||
} | ||
|
||
if (nameParts.length === 0) { | ||
return null | ||
} | ||
|
||
return nameParts.join(".") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict" | ||
|
||
const { | ||
getParserServices: getParserServicesFromTsEslint, | ||
} = require("@typescript-eslint/utils/eslint-utils") | ||
|
||
/** | ||
* Get the TypeScript parser services. | ||
* If TypeScript isn't present, returns `null`. | ||
* | ||
* @param {import('eslint').Rule.RuleContext} context - rule context | ||
* @returns {import('@typescript-eslint/parser').ParserServices | null} | ||
*/ | ||
module.exports = function getParserServices(context) { | ||
// Not using tseslint parser? | ||
if ( | ||
context.sourceCode.parserServices?.esTreeNodeToTSNodeMap == null || | ||
context.sourceCode.parserServices.tsNodeToESTreeNodeMap == null | ||
) { | ||
return null | ||
} | ||
|
||
return getParserServicesFromTsEslint(/** @type {any} */ (context), true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use strict" | ||
|
||
/** | ||
* Get the type of a node. | ||
* If TypeScript isn't present, returns `null`. | ||
* | ||
* @param {import('estree').Node} node - A node | ||
* @param {import('@typescript-eslint/parser').ParserServices} parserServices - A parserServices | ||
* @returns {import('typescript').Type | null} | ||
*/ | ||
module.exports = function getTypeOfNode(node, parserServices) { | ||
const { esTreeNodeToTSNodeMap, program } = parserServices | ||
if (program === null) { | ||
return null | ||
} | ||
const tsNode = esTreeNodeToTSNodeMap.get(/** @type {any} */ (node)) | ||
const checker = program.getTypeChecker() | ||
const nodeType = checker.getTypeAtLocation(tsNode) | ||
const constrained = checker.getBaseConstraintOfType(nodeType) | ||
return constrained ?? nodeType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// File needs to exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// File needs to exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// File needs to exists |
1 change: 1 addition & 0 deletions
1
tests/fixtures/no-sync/ignore-package/node_modules/aaa/index.d.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
6 changes: 6 additions & 0 deletions
6
tests/fixtures/no-sync/ignore-package/node_modules/aaa/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "test", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"aaa": "0.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["**/*"] | ||
} |
Oops, something went wrong.