Skip to content

Commit

Permalink
Update: add fixer for lines-around-directive (#7217)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and kaicataldo committed Sep 30, 2016
1 parent f8e8fab commit 18376cf
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/rules/lines-around-directive.md
@@ -1,5 +1,7 @@
# require or disallow newlines around directives (lines-around-directive)

(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule.

Directives are used in JavaScript to indicate to the execution environment that a script would like to opt into a feature such as `"strict mode"`. Directives are grouped together in a [directive prologue](http://www.ecma-international.org/ecma-262/7.0/#directive-prologue) at the top of either a file or function block and are applied to the scope in which they occur.

```js
Expand Down
9 changes: 8 additions & 1 deletion lib/rules/lines-around-directive.js
Expand Up @@ -37,7 +37,8 @@ module.exports = {
minProperties: 2
}
]
}]
}],
fixable: "whitespace"
},

create(context) {
Expand Down Expand Up @@ -88,6 +89,12 @@ module.exports = {
expected: expected ? "Expected" : "Unexpected",
value: node.expression.value,
location
},
fix(fixer) {
if (expected) {
return location === "before" ? fixer.insertTextBefore(node, "\n") : fixer.insertTextAfter(node, "\n");
}
return fixer.removeRange(location === "before" ? [node.range[0] - 1, node.range[0]] : [node.range[1], node.range[1] + 1]);
}
});
}
Expand Down

0 comments on commit 18376cf

Please sign in to comment.