Skip to content

Commit 63ecdd4

Browse files
authored
feat: add no-new-native-nonconstructor (#93)
1 parent 0a5ba04 commit 63ecdd4

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @fileoverview Add fixer to rule no-new-native-nonconstructor.
3+
* @author SukkaW <[email protected]>
4+
*/
5+
"use strict";
6+
7+
const ruleComposer = require("eslint-rule-composer");
8+
const utils = require("../utils");
9+
10+
const rule = utils.getFixableRule("no-new-native-nonconstructor", true);
11+
12+
module.exports = ruleComposer.mapReports(
13+
rule,
14+
problem => {
15+
problem.fix = fixer => {
16+
const parent = problem.node.parent;
17+
18+
return fixer.removeRange([parent.range[0], parent.range[0] + 4]);
19+
};
20+
return problem;
21+
}
22+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @fileoverview Tests for rule no-new-native-nonconstructor
3+
* @author SukkaW <[email protected]>
4+
*/
5+
"use strict";
6+
7+
//------------------------------------------------------------------------------
8+
// Requirements
9+
//------------------------------------------------------------------------------
10+
11+
const rule = require("../../../lib/rules/no-new-native-nonconstructor.js");
12+
const RuleTester = require("../../rule-tester.js").RuleTester;
13+
14+
//------------------------------------------------------------------------------
15+
// Tests
16+
//------------------------------------------------------------------------------
17+
18+
const ruleTester = new RuleTester();
19+
20+
ruleTester.run("no-new-native-nonconstructor", rule, {
21+
valid: [
22+
"Symbol('a')",
23+
"BigInt(42)"
24+
],
25+
invalid: [
26+
{
27+
code: "new Symbol('a')",
28+
output: "Symbol('a')",
29+
errors: 1
30+
},
31+
{
32+
code: "new BigInt(0x721)",
33+
output: "BigInt(0x721)",
34+
errors: 1
35+
}
36+
]
37+
});

0 commit comments

Comments
 (0)