-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-config): add no-useless-template-literals rule
- Loading branch information
Showing
6 changed files
with
57 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
packages/eslint-config/tests/typescript/no-useless-template-literals/.eslintrc.js
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,11 @@ | ||
module.exports = { | ||
rules: { | ||
/** | ||
* 禁止不必要的模板字符串 | ||
* @see {@link https://typescript-eslint.io/rules/no-useless-template-literals/} | ||
* @category TypeScript | ||
* @requires-type-information | ||
*/ | ||
'@typescript-eslint/no-useless-template-literals': 'error', | ||
}, | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/eslint-config/tests/typescript/no-useless-template-literals/bad.ts
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,19 @@ | ||
/* eslint-disable */ | ||
/* eslint-enable @typescript-eslint/no-useless-template-literals */ | ||
|
||
// errorCount 9 | ||
|
||
export default 1 | ||
|
||
const ab1 = `${'a'}${'b'}` | ||
const ab2 = `a${'b'}` | ||
|
||
const stringWithNumber = `${'1 + 1 = '}${2}` | ||
|
||
const stringWithBoolean = `${'true is '}${true}` | ||
|
||
const text = 'a' | ||
const wrappedText = `${text}` | ||
|
||
declare const intersectionWithString: string & { _brand: 'test-brand' } | ||
const wrappedIntersection = `${intersectionWithString}` |
17 changes: 17 additions & 0 deletions
17
packages/eslint-config/tests/typescript/no-useless-template-literals/good.ts
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,17 @@ | ||
/* eslint-disable */ | ||
/* eslint-enable @typescript-eslint/no-useless-template-literals */ | ||
|
||
export default 1 | ||
|
||
const ab1 = 'ab' | ||
const ab2 = 'ab' | ||
|
||
const stringWithNumber = `1 + 1 = 2` | ||
|
||
const stringWithBoolean = `true is true` | ||
|
||
const text = 'a' | ||
const wrappedText = text | ||
|
||
declare const intersectionWithString: string & { _brand: 'test-brand' } | ||
const wrappedIntersection = intersectionWithString |