Skip to content

Commit

Permalink
feat(eslint-config): add no-useless-template-literals rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ttionya committed Sep 12, 2024
1 parent 13f912f commit b681161
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-config/dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
"@typescript-eslint/no-use-before-define",
"@typescript-eslint/no-useless-constructor",
"@typescript-eslint/no-useless-empty-export",
"@typescript-eslint/no-useless-template-literals",
"@typescript-eslint/non-nullable-type-assertion-style",
"@typescript-eslint/parameter-properties",
"@typescript-eslint/prefer-enum-initializers",
Expand Down Expand Up @@ -519,7 +520,6 @@
"descriptionCN": "项目中应该存在但是缺少的规则。",
"expected": false,
"list": [
"@typescript-eslint/no-useless-template-literals",
"@typescript-eslint/prefer-destructuring",
"@typescript-eslint/prefer-find",
"@typescript-eslint/prefer-namespace-keyword",
Expand Down
9 changes: 8 additions & 1 deletion packages/eslint-config/dist/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ module.exports = {
* 禁止不安全的一元减号
* @see {@link https://typescript-eslint.io/rules/no-unsafe-unary-minus/}
* @category TypeScript
* @requires-type-information
*/
'@typescript-eslint/no-unsafe-unary-minus': 'error',

Expand Down Expand Up @@ -712,6 +711,14 @@ module.exports = {
*/
'@typescript-eslint/no-useless-empty-export': 'error',

/**
* 禁止不必要的模板字符串
* @see {@link https://typescript-eslint.io/rules/no-useless-template-literals/}
* @category TypeScript
* @requires-type-information
*/
'@typescript-eslint/no-useless-template-literals': 'error',

/**
* 必须使用 ! 而不是 as
* @see {@link https://typescript-eslint.io/rules/non-nullable-type-assertion-style/}
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/tests/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = {
'no-use-before-define': require('./no-use-before-define/.eslintrc.js'),
'no-useless-constructor': require('./no-useless-constructor/.eslintrc.js'),
'no-useless-empty-export': require('./no-useless-empty-export/.eslintrc.js'),
'no-useless-template-literals': require('./no-useless-template-literals/.eslintrc.js'),
'non-nullable-type-assertion-style': require('./non-nullable-type-assertion-style/.eslintrc.js'),
'parameter-properties': require('./parameter-properties/.eslintrc.js'),
'prefer-enum-initializers': require('./prefer-enum-initializers/.eslintrc.js'),
Expand Down
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',
},
}
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}`
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

0 comments on commit b681161

Please sign in to comment.