forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
- Loading branch information
1 parent
ccf5f9e
commit d27b2a8
Showing
7 changed files
with
303 additions
and
5 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,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(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(node) | ||
Check failure on line 16 in lib/util/get-type-of-node.js GitHub Actions / Lint
|
||
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
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