Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): [naming-convention] add
requiresQuotes
modifier (
#2813) Fixes #2761 Fixes #1483 This modifier simply matches any member name that requires quotes. To clarify: this does not match names that have quotes - only names that ***require*** quotes.
- Loading branch information
1 parent
dd0576a
commit 6fc8409
Showing
6 changed files
with
259 additions
and
38 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
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 @@ | ||
import * as ts from 'typescript'; | ||
|
||
function requiresQuoting( | ||
name: string, | ||
target: ts.ScriptTarget = ts.ScriptTarget.ESNext, | ||
): boolean { | ||
if (name.length === 0) { | ||
return true; | ||
} | ||
|
||
if (!ts.isIdentifierStart(name.charCodeAt(0), target)) { | ||
return true; | ||
} | ||
|
||
for (let i = 1; i < name.length; i += 1) { | ||
if (!ts.isIdentifierPart(name.charCodeAt(i), target)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export { requiresQuoting }; |
Oops, something went wrong.