Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new rule: no-var #1650

Merged
merged 1 commit into from Jan 13, 2015

Conversation

Projects
None yet
3 participants
@xjamundx
Copy link
Contributor

xjamundx commented Jan 11, 2015

Requires const or let instead of var when defining variables. Only applicable in ES6 environments.

@xjamundx xjamundx force-pushed the xjamundx:no-var branch from 45a1f06 to bfd78a8 Jan 11, 2015

//------------------------------------------------------------------------------

var eslintTester = new ESLintTester(eslint);
eslintTester.addRuleTest("lib/rules/generator-star", {

This comment has been minimized.

Copy link
@lo1tuma

lo1tuma Jan 11, 2015

Member

I think this should be lib/rules/no-var

@@ -167,6 +167,12 @@ These rules are purely matters of style and are quite subjective.
* [spaced-line-comment](spaced-line-comment.md) - require or disallow a space immediately following the `//` in a line comment (off by default)
* [wrap-regex](wrap-regex.md) - require regex literals to be wrapped in parentheses (off by default)

## ES6

This comment has been minimized.

Copy link
@nzakas

nzakas Jan 11, 2015

Member

I'd expand this to "ECMAScript 6" for clarity.

return {
"VariableDeclaration": function (node) {
if (node.kind === "var") {
context.report(node, "Please use \"let\" instead of \"var\".");

This comment has been minimized.

Copy link
@nzakas

nzakas Jan 11, 2015

Member

"let" or "const"

This comment has been minimized.

Copy link
@nzakas

nzakas Jan 11, 2015

Member

We usually phrase these messages in the form "Expected x" or "Unexpected y", so like "Unexpected var; use let or const instead."

valid: [
{
code: "const JOE = 'schmoe';",
args: [1]

This comment has been minimized.

Copy link
@nzakas

nzakas Jan 11, 2015

Member

Don't need args here.

You can use ecmaFeatures here with the latest checkin.

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Jan 11, 2015

Looks good!

@xjamundx xjamundx force-pushed the xjamundx:no-var branch from bfd78a8 to 06eb843 Jan 12, 2015

@xjamundx xjamundx force-pushed the xjamundx:no-var branch 2 times, most recently from b088458 to d71938c Jan 12, 2015

``
If you intend to use this rule, you must set `blockBindings` to `true` in the `ecmaFeatures` configuration
object, which will give ESLint the ability to read `let` and `const` variables.

This comment has been minimized.

Copy link
@nzakas

nzakas Jan 12, 2015

Member

Can you add a "When not to use it" section? We try to have that on each page to help people decide. Clearly in this case you wouldn't use it in an ES5 environment.

@xjamundx xjamundx force-pushed the xjamundx:no-var branch from d71938c to 01ae75b Jan 12, 2015

```js
let x = "y";
const CONFIG = {};
``

This comment has been minimized.

Copy link
@xjamundx

xjamundx Jan 12, 2015

Author Contributor

woops

@xjamundx xjamundx force-pushed the xjamundx:no-var branch from 01ae75b to 4c2197f Jan 12, 2015

@xjamundx

This comment has been minimized.

Copy link
Contributor Author

xjamundx commented Jan 13, 2015

Let me know if there are any other suggestions for getting this ready to merge.

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Jan 13, 2015

Looks good to me. Can you reformat your commit message to be:
"New: no-var rule (refs #1617)"

Jamund Ferguson

@xjamundx xjamundx force-pushed the xjamundx:no-var branch from 4c2197f to 7a69501 Jan 13, 2015

nzakas added a commit that referenced this pull request Jan 13, 2015

@nzakas nzakas merged commit c43dcdf into eslint:master Jan 13, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.