Skip to content

Commit

Permalink
New: add fixer for "no-new-symbol" (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Feb 12, 2019
1 parent 2276eb6 commit 95d29d0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/rules/no-new-symbol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @fileoverview add fixer to rule no-new-symbol.
* @author Pig Fang<g-plane@hotmail.com>
*/
"use strict";

const ruleComposer = require("eslint-rule-composer");
const utils = require("../utils");

const rule = utils.getFixableRule("no-new-symbol");

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;
}
);
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Name | ✔️ | 🛠 | Description
[no-alert](https://eslint.org/docs/rules/no-alert) | | 🛠 | disallow the use of `alert`, `confirm`, and `prompt`
[no-console](https://eslint.org/docs/rules/no-console) | ✔️ | 🛠 | disallow the use of `console`
[no-debugger](https://eslint.org/docs/rules/no-debugger) | ✔️ | 🛠 | disallow the use of `debugger`
[no-new-symbol](https://eslint.org/docs/rules/no-new-symbol) | | 🛠 | disallow `new` operators with the `Symbol` object
[no-plusplus](https://eslint.org/docs/rules/no-plusplus) | ✔️ | 🛠 | disallow the unary operators `++` and `--`
[no-prototype-builtins](https://eslint.org/docs/rules/no-prototype-builtins) | | 🛠 | disallow calling some `Object.prototype` methods directly on objects
[no-useless-concat](https://eslint.org/docs/rules/no-useless-concat) | | 🛠 | disallow unnecessary concatenation of literals or template literals
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/rules/no-new-symbol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @fileoverview Tests for rule no-new-symbol
* @author Pig Fang <g-plane@hotmail.com>
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require("../../../lib/rules/no-new-symbol");
const RuleTester = require("eslint").RuleTester;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ env: { es6: true } });
const errors = [{ type: "Identifier" }];

ruleTester.run("no-new-symbol", rule, {
valid: [
"Symbol('a')"
],
invalid: [
{
code: "new Symbol('a')",
output: "Symbol('a')",
errors
}
]
});

0 comments on commit 95d29d0

Please sign in to comment.