-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
no-new-native-nonconstructor
(#93)
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/autofix/lib/rules/no-new-native-nonconstructor.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,22 @@ | ||
/** | ||
* @fileoverview Add fixer to rule no-new-native-nonconstructor. | ||
* @author SukkaW <[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
const ruleComposer = require("eslint-rule-composer"); | ||
const utils = require("../utils"); | ||
|
||
const rule = utils.getFixableRule("no-new-native-nonconstructor", true); | ||
|
||
module.exports = ruleComposer.mapReports( | ||
rule, | ||
problem => { | ||
problem.fix = fixer => { | ||
const parent = problem.node.parent; | ||
|
||
return fixer.removeRange([parent.range[0], parent.range[0] + 4]); | ||
}; | ||
return problem; | ||
} | ||
); |
37 changes: 37 additions & 0 deletions
37
packages/autofix/tests/lib/rules/no-new-native-nonconstructor.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,37 @@ | ||
/** | ||
* @fileoverview Tests for rule no-new-native-nonconstructor | ||
* @author SukkaW <[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = require("../../../lib/rules/no-new-native-nonconstructor.js"); | ||
const RuleTester = require("../../rule-tester.js").RuleTester; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
const ruleTester = new RuleTester(); | ||
|
||
ruleTester.run("no-new-native-nonconstructor", rule, { | ||
valid: [ | ||
"Symbol('a')", | ||
"BigInt(42)" | ||
], | ||
invalid: [ | ||
{ | ||
code: "new Symbol('a')", | ||
output: "Symbol('a')", | ||
errors: 1 | ||
}, | ||
{ | ||
code: "new BigInt(0x721)", | ||
output: "BigInt(0x721)", | ||
errors: 1 | ||
} | ||
] | ||
}); |