-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: add fixer for "no-new-symbol" (#23)
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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-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; | ||
} | ||
); |
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
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,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 | ||
} | ||
] | ||
}); |