Skip to content

Commit

Permalink
feat(eslint-config): add no-unsafe-unary-minus rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ttionya committed Sep 12, 2024
1 parent 5614678 commit 13f912f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-config/dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
"@typescript-eslint/no-unnecessary-condition",
"@typescript-eslint/no-unnecessary-qualifier",
"@typescript-eslint/no-unnecessary-type-arguments",
"@typescript-eslint/no-unsafe-unary-minus",
"@typescript-eslint/no-unused-expressions",
"@typescript-eslint/no-use-before-define",
"@typescript-eslint/no-useless-constructor",
Expand Down Expand Up @@ -518,7 +519,6 @@
"descriptionCN": "项目中应该存在但是缺少的规则。",
"expected": false,
"list": [
"@typescript-eslint/no-unsafe-unary-minus",
"@typescript-eslint/no-useless-template-literals",
"@typescript-eslint/prefer-destructuring",
"@typescript-eslint/prefer-find",
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-config/dist/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,14 @@ module.exports = {
*/
'@typescript-eslint/no-unsafe-return': 'off',

/**
* 禁止不安全的一元减号
* @see {@link https://typescript-eslint.io/rules/no-unsafe-unary-minus/}
* @category TypeScript
* @requires-type-information
*/
'@typescript-eslint/no-unsafe-unary-minus': 'error',

/**
* 禁止无用的表达式
* @see {@link https://typescript-eslint.io/rules/no-unused-expressions/}
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 @@ -64,6 +64,7 @@ module.exports = {
'no-unsafe-declaration-merging': require('./no-unsafe-declaration-merging/.eslintrc.js'),
'no-unsafe-member-access': require('./no-unsafe-member-access/.eslintrc.js'),
'no-unsafe-return': require('./no-unsafe-return/.eslintrc.js'),
'no-unsafe-unary-minus': require('./no-unsafe-unary-minus/.eslintrc.js'),
'no-unused-expressions': require('./no-unused-expressions/.eslintrc.js'),
'no-use-before-define': require('./no-use-before-define/.eslintrc.js'),
'no-useless-constructor': require('./no-useless-constructor/.eslintrc.js'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 禁止不安全的一元减号
* @see {@link https://typescript-eslint.io/rules/no-unsafe-unary-minus/}
* @category TypeScript
*/
'@typescript-eslint/no-unsafe-unary-minus': 'error',
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
/* eslint-enable @typescript-eslint/no-unsafe-unary-minus */

// errorCount 2

export default 1

declare const a: string
;-a

declare const b: {}
;-b
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
/* eslint-enable @typescript-eslint/no-unsafe-unary-minus */

export default 1

;-42
;-42n

declare const a: number
;-a

declare const b: number
;-b

declare const c: number | bigint
;-c

declare const d: any
;-d

declare const e: 1 | 2
;-e

0 comments on commit 13f912f

Please sign in to comment.