Skip to content

Commit

Permalink
feat: add no-new-native-nonconstructor (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Jul 1, 2024
1 parent 0a5ba04 commit 63ecdd4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/autofix/lib/rules/no-new-native-nonconstructor.js
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 packages/autofix/tests/lib/rules/no-new-native-nonconstructor.js
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
}
]
});

0 comments on commit 63ecdd4

Please sign in to comment.