├── tests
├── fixtures
│ ├── file-finder
│ │ ├── empty
│ │ ├── subdir
│ │ │ ├── empty
│ │ │ ├── empty2
│ │ │ ├── subsubdir
│ │ │ │ ├── empty
│ │ │ │ └── subsubsubdir
│ │ │ │ │ └── empty
│ │ │ └── xvgRHtyH56756764535jkJ6jthty65tyhteHTEY
│ │ ├── package.json
│ │ │ └── empty
│ │ ├── .eslintignore
│ │ └── xvgRHtyH56756764535jkJ6jthty65tyhteHTEY
│ ├── formatters
│ │ ├── .ignoreme
│ │ ├── simple.js
│ │ └── test
│ │ │ └── simple.js
│ ├── rules
│ │ ├── fixture-rule.js
│ │ ├── .eslintignore
│ │ ├── .jshintignore
│ │ ├── test-multi-rulesdirs.js
│ │ ├── not-a-rule.yml
│ │ ├── missing-rule.json
│ │ ├── test
│ │ │ └── test-custom-rule.js
│ │ ├── wrong
│ │ │ └── custom-rule.js
│ │ ├── eslint.json
│ │ ├── multi-rulesdirs.json
│ │ ├── dir2
│ │ │ └── no-literals.js
│ │ ├── dir1
│ │ │ └── no-strings.js
│ │ └── custom-rule.js
│ ├── syntax-error.js
│ ├── eslintrc
│ │ ├── ignored.json
│ │ ├── quotes.js
│ │ ├── .eslintignore
│ │ └── .eslintrc
│ ├── glob-util
│ │ ├── hidden
│ │ │ └── .foo.js
│ │ ├── ignored
│ │ │ ├── foo.js
│ │ │ └── .eslintignore
│ │ ├── one-js-file
│ │ │ └── baz.js
│ │ └── two-js-files
│ │ │ ├── bar.js
│ │ │ └── foo.js
│ ├── traverse
│ │ ├── .hidden_file.js
│ │ ├── found.js
│ │ ├── .hidden_dir
│ │ │ └── dummy.js
│ │ └── found.js2
│ ├── config-file
│ │ ├── js
│ │ │ ├── .eslintrc
│ │ │ └── .eslintrc.js
│ │ ├── json
│ │ │ ├── .eslintrc
│ │ │ └── .eslintrc.json
│ │ ├── yaml
│ │ │ ├── .eslintrc
│ │ │ ├── .eslintrc.yml
│ │ │ └── .eslintrc.yaml
│ │ ├── yml
│ │ │ ├── .eslintrc
│ │ │ └── .eslintrc.yml
│ │ ├── legacy
│ │ │ └── .eslintrc
│ │ ├── extends
│ │ │ └── .eslintrc.yml
│ │ └── package-json
│ │ │ └── package.json
│ ├── configurations
│ │ ├── empty
│ │ │ ├── .eslintrc
│ │ │ └── empty.json
│ │ ├── undef-error.json
│ │ ├── quotes-error.json
│ │ ├── single-quotes
│ │ │ ├── subdir
│ │ │ │ └── .eslintrc
│ │ │ └── .eslintrc
│ │ ├── semi-error.json
│ │ ├── env-browser.yaml
│ │ ├── env-nashorn.json
│ │ ├── env-webextensions.json
│ │ ├── env-node.json
│ │ ├── cwd
│ │ │ └── .eslintrc
│ │ ├── env-browser.json
│ │ ├── my-awesome-config
│ │ ├── comments.json
│ │ ├── plugins-without-prefix.json
│ │ ├── plugins-with-prefix.json
│ │ ├── plugins-without-prefix-with-namespace.json
│ │ ├── plugins-with-prefix-and-namespace.json
│ │ └── processors.json
│ ├── fixmode
│ │ ├── ok.js
│ │ ├── quotes.js
│ │ └── quotes-semi-eqeqeq.js
│ ├── .eslintrc
│ ├── config-hierarchy
│ │ ├── shared
│ │ │ ├── a
│ │ │ │ ├── index.js
│ │ │ │ └── .eslintrc
│ │ │ └── b
│ │ │ │ ├── index.js
│ │ │ │ └── .eslintrc
│ │ ├── broken
│ │ │ ├── process-exit.js
│ │ │ ├── console-wrong-quotes.js
│ │ │ ├── override-conf.yaml
│ │ │ ├── add-conf.yaml
│ │ │ ├── plugins
│ │ │ │ ├── .eslintrc
│ │ │ │ └── console-wrong-quotes.js
│ │ │ ├── plugins2
│ │ │ │ ├── console-wrong-quotes.js
│ │ │ │ └── .eslintrc
│ │ │ ├── subbroken
│ │ │ │ ├── console-wrong-quotes.js
│ │ │ │ ├── subsubbroken
│ │ │ │ │ ├── console-wrong-quotes.js
│ │ │ │ │ └── .eslintrc
│ │ │ │ └── .eslintrc
│ │ │ ├── .eslintrc
│ │ │ ├── console-wrong-quotes-node.js
│ │ │ ├── package.json
│ │ │ ├── override-env-conf.yaml
│ │ │ └── wrong-quotes.js
│ │ ├── packagejson
│ │ │ ├── wrong-quotes.js
│ │ │ ├── subdir
│ │ │ │ ├── wrong-quotes.js
│ │ │ │ ├── subsubdir
│ │ │ │ │ ├── wrong-quotes.js
│ │ │ │ │ ├── subsubsubdir
│ │ │ │ │ │ ├── wrong-quotes.js
│ │ │ │ │ │ └── package.json
│ │ │ │ │ └── package.json
│ │ │ │ └── package.json
│ │ │ ├── .eslintrc
│ │ │ └── package.json
│ │ ├── fileexts
│ │ │ ├── subdir
│ │ │ │ ├── .eslintrc.yml
│ │ │ │ └── subsubdir
│ │ │ │ │ └── .eslintrc.json
│ │ │ └── .eslintrc.js
│ │ ├── personal-config
│ │ │ ├── home-folder
│ │ │ │ ├── project
│ │ │ │ │ ├── package.json
│ │ │ │ │ └── .eslintrc
│ │ │ │ └── .eslintrc.json
│ │ │ ├── project-with-config
│ │ │ │ ├── package.json
│ │ │ │ ├── .eslintrc
│ │ │ │ └── subfolder
│ │ │ │ │ └── .eslintrc
│ │ │ └── project-without-config
│ │ │ │ └── package.json
│ │ ├── root-true
│ │ │ └── parent
│ │ │ │ ├── root
│ │ │ │ ├── wrong-semi.js
│ │ │ │ └── .eslintrc
│ │ │ │ └── .eslintrc
│ │ └── overwrite-ecmaFeatures
│ │ │ ├── child
│ │ │ └── .eslintrc
│ │ │ └── .eslintrc
│ ├── process-exit.js
│ ├── .eslintignore
│ ├── .eslintignore4
│ ├── globals-browser.js
│ ├── missing-semicolon.js
│ ├── single-quoted.js
│ ├── undef.js
│ ├── cli-engine
│ │ ├── .eslintignore
│ │ ├── .eslintignore2
│ │ ├── _node_modules
│ │ │ └── text.js
│ │ └── console.js
│ ├── files
│ │ ├── .eslintrc
│ │ ├── .bar.js
│ │ ├── foo.js
│ │ └── foo.js2
│ ├── packagejson
│ │ ├── quotes.js
│ │ └── package.json
│ ├── config-extends
│ │ ├── package2
│ │ │ ├── subdir
│ │ │ │ └── foo.js
│ │ │ └── .eslintrc
│ │ ├── package3
│ │ │ ├── subdir
│ │ │ │ └── foo.js
│ │ │ └── .eslintrc
│ │ ├── scoped-package3
│ │ │ ├── foo.js
│ │ │ └── .eslintrc
│ │ ├── error.json
│ │ ├── array
│ │ │ ├── .eslintrc2
│ │ │ ├── .eslintrc1
│ │ │ └── .eslintrc
│ │ ├── package.json
│ │ ├── subdir
│ │ │ ├── .eslintrc
│ │ │ └── subsubdir
│ │ │ │ ├── subsubsubdir
│ │ │ │ └── deepest.json
│ │ │ │ └── deeper.json
│ │ ├── deep.json
│ │ ├── js
│ │ │ └── .eslintrc
│ │ ├── .eslintrc
│ │ ├── scoped-package5
│ │ │ └── .eslintrc
│ │ ├── scoped-package6
│ │ │ └── .eslintrc
│ │ ├── package
│ │ │ └── .eslintrc
│ │ ├── scoped-package2
│ │ │ └── .eslintrc
│ │ ├── package4
│ │ │ └── .eslintrc
│ │ ├── scoped-package
│ │ │ └── .eslintrc
│ │ ├── scoped-package4
│ │ │ └── .eslintrc
│ │ ├── scoped-package7
│ │ │ └── .eslintrc
│ │ └── scoped-package8
│ │ │ └── .eslintrc
│ ├── .eslintignore2
│ ├── globals-node.js
│ ├── cache
│ │ └── src
│ │ │ ├── test-file.js
│ │ │ └── fail-file.js
│ ├── disable-inline-config.js
│ ├── passing.js
│ ├── globals
│ │ └── conf.yaml
│ ├── processors
│ │ ├── test
│ │ │ └── test-processor.txt
│ │ └── custom-processor.js
│ ├── environments
│ │ ├── disable.yaml
│ │ └── fake.yaml
│ ├── .eslintignore3
│ ├── globals-nashorn.js
│ ├── max-warnings
│ │ ├── .eslintrc
│ │ └── six-warnings.js
│ ├── globals-webextensions.js
│ ├── parsers
│ │ ├── no-line-error.js
│ │ └── line-error.js
│ ├── shebang.js
│ └── testers
│ │ └── rule-tester
│ │ ├── no-eval.js
│ │ ├── modify-ast.js
│ │ ├── no-test-filename
│ │ ├── no-invalid-args.js
│ │ ├── no-test-settings.js
│ │ ├── no-invalid-schema.js
│ │ ├── no-schema-violation.js
│ │ ├── no-var.js
│ │ ├── no-test-global.js
│ │ ├── modify-ast-at-first.js
│ │ └── modify-ast-at-last.js
├── lib
│ ├── .eslintrc
│ ├── api.js
│ └── rules
│ │ ├── no-with.js
│ │ ├── no-delete-var.js
│ │ ├── no-debugger.js
│ │ ├── no-new.js
│ │ ├── new-parens.js
│ │ ├── no-negated-in-lhs.js
│ │ ├── no-regex-spaces.js
│ │ ├── no-new-object.js
│ │ ├── no-obj-calls.js
│ │ ├── no-div-regex.js
│ │ ├── no-sync.js
│ │ ├── no-proto.js
│ │ ├── no-undef-init.js
│ │ ├── no-eval.js
│ │ ├── no-caller.js
│ │ ├── no-console.js
│ │ ├── no-lonely-if.js
│ │ ├── no-nested-ternary.js
│ │ ├── no-ternary.js
│ │ ├── no-multi-str.js
│ │ ├── no-new-func.js
│ │ ├── no-empty-label.js
│ │ ├── no-eq-null.js
│ │ ├── no-octal.js
│ │ ├── wrap-regex.js
│ │ ├── no-floating-decimal.js
│ │ ├── no-new-require.js
│ │ ├── guard-for-in.js
│ │ ├── no-iterator.js
│ │ ├── no-sparse-arrays.js
│ │ └── no-script-url.js
├── tests.htm
└── bench
│ ├── xform-rules.js
│ └── bench.js
├── .gitattributes
├── .eslintrc.yml
├── docs
└── rules
│ ├── .gitattributes
│ ├── no-delete-var.md
│ ├── space-unary-word-ops.md
│ ├── no-empty-label.md
│ ├── no-script-url.md
│ ├── no-div-regex.md
│ ├── require-yield.md
│ ├── wrap-regex.md
│ ├── no-dupe-args.md
│ ├── no-with.md
│ ├── no-spaced-func.md
│ ├── no-empty-class.md
│ ├── space-return-throw-case.md
│ ├── no-octal-escape.md
│ ├── no-label-var.md
│ ├── new-parens.md
│ ├── no-multi-str.md
│ ├── no-space-before-semi.md
│ ├── no-empty-character-class.md
│ ├── no-eq-null.md
│ ├── no-control-regex.md
│ ├── no-native-reassign.md
│ ├── no-new.md
│ ├── no-self-compare.md
│ ├── no-proto.md
│ ├── no-dupe-keys.md
│ ├── no-debugger.md
│ ├── no-negated-in-lhs.md
│ ├── no-nested-ternary.md
│ ├── no-wrap-func.md
│ ├── use-isnan.md
│ ├── no-extra-semi.md
│ ├── eol-last.md
│ ├── no-obj-calls.md
│ ├── func-names.md
│ ├── no-new-func.md
│ ├── no-octal.md
│ ├── no-ternary.md
│ ├── prefer-template.md
│ ├── no-comma-dangle.md
│ ├── no-arrow-condition.md
│ └── no-invalid-regexp.md
├── .codeclimate.yml
├── .eslintignore
├── .gitignore
├── CONTRIBUTING.md
├── lib
├── api.js
├── formatters
│ ├── json.js
│ └── jslint-xml.js
├── rules
│ ├── no-with.js
│ ├── no-debugger.js
│ ├── no-ternary.js
│ ├── no-continue.js
│ ├── no-console.js
│ ├── no-octal.js
│ ├── no-delete-var.js
│ ├── no-new-object.js
│ ├── no-var.js
│ ├── no-new-require.js
│ ├── no-new.js
│ ├── no-eval.js
│ ├── no-nested-ternary.js
│ ├── no-negated-in-lhs.js
│ ├── no-div-regex.js
│ ├── no-new-wrappers.js
│ ├── use-isnan.js
│ ├── no-undefined.js
│ ├── no-obj-calls.js
│ ├── no-sync.js
│ ├── no-proto.js
│ ├── new-parens.js
│ ├── no-empty-label.js
│ ├── no-iterator.js
│ ├── no-process-env.js
│ ├── no-caller.js
│ ├── no-void.js
│ ├── no-sparse-arrays.js
│ ├── no-script-url.js
│ ├── no-eq-null.js
│ ├── no-undef-init.js
│ ├── no-empty-pattern.js
│ ├── no-floating-decimal.js
│ ├── no-process-exit.js
│ ├── no-lonely-if.js
│ ├── no-self-compare.js
│ ├── global-require.js
│ ├── guard-for-in.js
│ ├── no-duplicate-case.js
│ ├── no-array-constructor.js
│ ├── no-regex-spaces.js
│ ├── no-new-func.js
│ ├── no-ex-assign.js
│ ├── no-labels.js
│ ├── no-octal-escape.js
│ ├── no-path-concat.js
│ ├── no-plusplus.js
│ ├── wrap-regex.js
│ ├── no-const-assign.js
│ └── no-restricted-syntax.js
├── logging.js
├── util
│ └── keywords.js
└── load-rules.js
├── .travis.yml
├── conf
├── blank-script.json
└── replacements.json
├── .editorconfig
├── ISSUE_CREATE.md
├── appveyor.yml
├── packages
└── eslint-config-eslint
│ ├── package.json
│ ├── LICENSE
│ ├── README.md
│ └── index.js
├── scripts
└── bundle.sh
└── LICENSE
/tests/fixtures/file-finder/empty:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/formatters/.ignoreme:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/fixture-rule.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/syntax-error.js:
--------------------------------------------------------------------------------
1 | {}}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/eslintrc/ignored.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/subdir/empty:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/subdir/empty2:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/glob-util/hidden/.foo.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/glob-util/ignored/foo.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/glob-util/one-js-file/baz.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/.eslintignore:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/.jshintignore:
--------------------------------------------------------------------------------
1 | **/*
2 |
--------------------------------------------------------------------------------
/tests/fixtures/traverse/.hidden_file.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/traverse/found.js:
--------------------------------------------------------------------------------
1 | 'test.js'
--------------------------------------------------------------------------------
/tests/fixtures/config-file/js/.eslintrc:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/json/.eslintrc:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/yaml/.eslintrc:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/yml/.eslintrc:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/empty/.eslintrc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/empty/empty.json:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/package.json/empty:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/fixmode/ok.js:
--------------------------------------------------------------------------------
1 | var msg = "hi";
2 |
--------------------------------------------------------------------------------
/tests/fixtures/glob-util/two-js-files/bar.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/glob-util/two-js-files/foo.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/traverse/.hidden_dir/dummy.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/traverse/found.js2:
--------------------------------------------------------------------------------
1 | 'test.js'
2 |
--------------------------------------------------------------------------------
/tests/lib/.eslintrc:
--------------------------------------------------------------------------------
1 | env:
2 | mocha: true
3 |
--------------------------------------------------------------------------------
/tests/fixtures/.eslintrc:
--------------------------------------------------------------------------------
1 | rules:
2 | strict: 0
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/yaml/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/shared/a/index.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/shared/b/index.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/subdir/subsubdir/empty:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/process-exit.js:
--------------------------------------------------------------------------------
1 | process.exit(0);
2 |
--------------------------------------------------------------------------------
/tests/fixtures/.eslintignore:
--------------------------------------------------------------------------------
1 | **/*.json
2 | **/*.js
3 |
--------------------------------------------------------------------------------
/tests/fixtures/.eslintignore4:
--------------------------------------------------------------------------------
1 | /dir
2 | !/dir/foo.js
3 |
--------------------------------------------------------------------------------
/tests/fixtures/eslintrc/quotes.js:
--------------------------------------------------------------------------------
1 | var str = "quotes!";
2 |
--------------------------------------------------------------------------------
/tests/fixtures/fixmode/quotes.js:
--------------------------------------------------------------------------------
1 | var msg = 'hi' + foo;
2 |
--------------------------------------------------------------------------------
/tests/fixtures/globals-browser.js:
--------------------------------------------------------------------------------
1 | window.alert("foo");
2 |
--------------------------------------------------------------------------------
/tests/fixtures/missing-semicolon.js:
--------------------------------------------------------------------------------
1 | console.log("bar")
2 |
--------------------------------------------------------------------------------
/tests/fixtures/single-quoted.js:
--------------------------------------------------------------------------------
1 | console.log('bar');
2 |
--------------------------------------------------------------------------------
/tests/fixtures/undef.js:
--------------------------------------------------------------------------------
1 | var bar = baz;
2 | bat = bar;
3 |
--------------------------------------------------------------------------------
/tests/fixtures/cli-engine/.eslintignore:
--------------------------------------------------------------------------------
1 | **/_node_modules
2 |
--------------------------------------------------------------------------------
/tests/fixtures/cli-engine/.eslintignore2:
--------------------------------------------------------------------------------
1 | tests/fixtures
2 |
--------------------------------------------------------------------------------
/tests/fixtures/cli-engine/_node_modules/text.js:
--------------------------------------------------------------------------------
1 | 'text';
2 |
--------------------------------------------------------------------------------
/tests/fixtures/cli-engine/console.js:
--------------------------------------------------------------------------------
1 | console.log("hi");
2 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/subdir/subsubdir/subsubsubdir/empty:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/files/.eslintrc:
--------------------------------------------------------------------------------
1 | settings:
2 | jsx: true
3 |
--------------------------------------------------------------------------------
/tests/fixtures/glob-util/ignored/.eslintignore:
--------------------------------------------------------------------------------
1 | **/foo.js
2 |
--------------------------------------------------------------------------------
/tests/fixtures/packagejson/quotes.js:
--------------------------------------------------------------------------------
1 | var str = "quotes!";
2 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/test-multi-rulesdirs.js:
--------------------------------------------------------------------------------
1 | "Points!";
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package2/subdir/foo.js:
--------------------------------------------------------------------------------
1 | var a = 1;
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package3/subdir/foo.js:
--------------------------------------------------------------------------------
1 | var a = 1;
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package3/foo.js:
--------------------------------------------------------------------------------
1 | var a = 1;
2 |
--------------------------------------------------------------------------------
/tests/fixtures/eslintrc/.eslintignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | **/*.json
3 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/.eslintignore:
--------------------------------------------------------------------------------
1 | **/*.json
2 | **/*.js
3 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/xvgRHtyH56756764535jkJ6jthty65tyhteHTEY:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/.eslintignore2:
--------------------------------------------------------------------------------
1 | undef.js
2 | ./undef2.js
3 | undef3.js
4 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/yml/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | env:
2 | node: true
3 |
--------------------------------------------------------------------------------
/tests/fixtures/file-finder/subdir/xvgRHtyH56756764535jkJ6jthty65tyhteHTEY:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/yaml/.eslintrc.yaml:
--------------------------------------------------------------------------------
1 | env:
2 | browser: true
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/process-exit.js:
--------------------------------------------------------------------------------
1 | process.exit(0);
2 |
--------------------------------------------------------------------------------
/tests/fixtures/globals-node.js:
--------------------------------------------------------------------------------
1 | var foo = __dirname;
2 | console.log(foo);
3 |
--------------------------------------------------------------------------------
/tests/fixtures/cache/src/test-file.js:
--------------------------------------------------------------------------------
1 | var abc = 2;
2 |
3 | console.log(abc);
4 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/wrong-quotes.js:
--------------------------------------------------------------------------------
1 | var str = 'quotes';
2 |
--------------------------------------------------------------------------------
/tests/fixtures/files/.bar.js:
--------------------------------------------------------------------------------
1 | var bar = "
Hello world!
";
2 | bar(bar);
3 |
--------------------------------------------------------------------------------
/tests/fixtures/files/foo.js:
--------------------------------------------------------------------------------
1 | var foo = "Hello world!
";
2 | foo(foo);
3 |
--------------------------------------------------------------------------------
/tests/fixtures/files/foo.js2:
--------------------------------------------------------------------------------
1 | var foo = "Hello world!
";
2 | foo(foo);
3 |
--------------------------------------------------------------------------------
/tests/fixtures/cache/src/fail-file.js:
--------------------------------------------------------------------------------
1 | var abc = 'some value'
2 | console.log(foo);
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/console-wrong-quotes.js:
--------------------------------------------------------------------------------
1 | console.log('bar');
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/override-conf.yaml:
--------------------------------------------------------------------------------
1 | rules:
2 | quotes: 0
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/fileexts/subdir/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | rules:
2 | eqeqeq: 2
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/home-folder/project/package.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/project-with-config/package.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/disable-inline-config.js:
--------------------------------------------------------------------------------
1 | console.log('bar'); // eslint-disable-line
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/error.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./non-existant.json"
3 | }
4 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/add-conf.yaml:
--------------------------------------------------------------------------------
1 | rules:
2 | semi: [1, "never"]
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/subdir/wrong-quotes.js:
--------------------------------------------------------------------------------
1 | var str = 'quotes';
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/project-without-config/package.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/root-true/parent/root/wrong-semi.js:
--------------------------------------------------------------------------------
1 | var str = 'quotes'
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/shared/b/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "example"
3 | }
4 |
--------------------------------------------------------------------------------
/tests/fixtures/passing.js:
--------------------------------------------------------------------------------
1 | var foo = "bar";
2 | if (foo) {
3 | foo = "bar2";
4 | }
5 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Convert text file line endings to lf
2 | * text=auto
3 |
4 | *.js text
5 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/plugins/.eslintrc:
--------------------------------------------------------------------------------
1 | plugins:
2 | ["example"]
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/plugins/console-wrong-quotes.js:
--------------------------------------------------------------------------------
1 | console.log('bar');
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/plugins2/console-wrong-quotes.js:
--------------------------------------------------------------------------------
1 | console.log('bar');
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/subbroken/console-wrong-quotes.js:
--------------------------------------------------------------------------------
1 | console.log('bar');
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/.eslintrc:
--------------------------------------------------------------------------------
1 | rules:
2 | quotes: [2, "double"]
3 |
--------------------------------------------------------------------------------
/tests/fixtures/fixmode/quotes-semi-eqeqeq.js:
--------------------------------------------------------------------------------
1 | var msg = 'hi'
2 | if (msg == 'hi') {
3 |
4 | }
5 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/subdir/subsubdir/wrong-quotes.js:
--------------------------------------------------------------------------------
1 | var str = 'quotes';
2 |
--------------------------------------------------------------------------------
/tests/fixtures/globals/conf.yaml:
--------------------------------------------------------------------------------
1 | {
2 | "globals": {
3 | "foo": true
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/processors/test/test-processor.txt:
--------------------------------------------------------------------------------
1 | function a() {
2 | console.log("Test");
3 | }
4 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/legacy/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | rules: {
3 | eqeqeq: 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/undef-error.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "no-undef": 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/environments/disable.yaml:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": false
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/not-a-rule.yml:
--------------------------------------------------------------------------------
1 | - This YAML file should be ignored when loading the rules directory.
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/subbroken/subsubbroken/console-wrong-quotes.js:
--------------------------------------------------------------------------------
1 | console.log('bar');
2 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/subdir/subsubdir/subsubsubdir/wrong-quotes.js:
--------------------------------------------------------------------------------
1 | var str = 'quotes';
2 |
--------------------------------------------------------------------------------
/tests/fixtures/eslintrc/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "quotes": [2, "single"]
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/missing-rule.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "missing-rule": 1
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/extends/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | extends: ../package-json/package.json
2 | rules:
3 | booya: 2
4 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/.eslintrc:
--------------------------------------------------------------------------------
1 | env:
2 | node: true
3 | rules:
4 | quotes: [2, "double"]
5 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/plugins2/.eslintrc:
--------------------------------------------------------------------------------
1 | plugins:
2 | ["example", "eslint-plugin-test"]
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/json/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "quotes": [2, "double"]
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/subbroken/.eslintrc:
--------------------------------------------------------------------------------
1 | rules:
2 | no-console: 1
3 | quotes: [2, "single"]
4 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/test/test-custom-rule.js:
--------------------------------------------------------------------------------
1 | var test = function() {
2 |
3 | };
4 |
5 | var foo = 5;
6 | test(foo);
7 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/console-wrong-quotes-node.js:
--------------------------------------------------------------------------------
1 |
2 | /*eslint-env node*/
3 |
4 | console.log('bar');
5 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "",
4 | "eslintConfig": {}
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/quotes-error.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "quotes": [2, "double"]
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/single-quotes/subdir/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "no-new": 0
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/environments/fake.yaml:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "blah": true,
4 | "es6": true
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/.eslintrc.yml:
--------------------------------------------------------------------------------
1 | root: true
2 |
3 | env:
4 | node: true
5 |
6 | extends:
7 | "./packages/eslint-config-eslint/default.yml"
8 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/js/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | rules: {
3 | semi: [2, "always"]
4 | }
5 | };
6 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/semi-error.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "semi": 1,
4 | "strict": 0
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/tests/fixtures/.eslintignore3:
--------------------------------------------------------------------------------
1 | # this comment lines
2 |
3 | # and empty strings
4 |
5 | # should be ignored
6 |
7 | this_one_not
8 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/subbroken/subsubbroken/.eslintrc:
--------------------------------------------------------------------------------
1 | rules:
2 | no-console: 0
3 | quotes: [1, "double"]
4 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/overwrite-ecmaFeatures/child/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "commonjs": true
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/globals-nashorn.js:
--------------------------------------------------------------------------------
1 | var path = __DIR__;
2 | print(path);
3 | load('something.js');
4 | loadWithNewGlobal('other.js');
5 |
--------------------------------------------------------------------------------
/tests/fixtures/max-warnings/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "quotes": [1, "single"]
4 | },
5 | "root": true
6 | }
7 |
--------------------------------------------------------------------------------
/docs/rules/.gitattributes:
--------------------------------------------------------------------------------
1 | # Avoid line-ending conversion for linebreak-style, or else example linting breaks
2 | linebreak-style.md -text
3 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/fileexts/subdir/subsubdir/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/wrong/custom-rule.js:
--------------------------------------------------------------------------------
1 | module.exports = function() {
2 |
3 | "use strict";
4 | return (null).something;
5 | };
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/overwrite-ecmaFeatures/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaFeatures": {
3 | "globalReturn": false
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/env-browser.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | env:
3 | browser: true
4 |
5 | rules:
6 | no-alert: 0
7 | no-undef: 2
8 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/home-folder/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "home-folder-rule": 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/shared/a/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "example",
3 | "rules": {
4 | "quotes": [ 2, "single" ]
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/env-nashorn.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "nashorn": true
4 | },
5 | "rules": {
6 | "no-undef": 2
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/home-folder/project/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "project-level-rule": 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/project-with-config/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "project-level-rule": 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.codeclimate.yml:
--------------------------------------------------------------------------------
1 | languages:
2 | JavaScript: true
3 |
4 | exclude_paths:
5 | - tests/**
6 |
7 | engines:
8 | eslint:
9 | enabled: true
10 |
--------------------------------------------------------------------------------
/tests/fixtures/config-file/package-json/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "eslintConfig": {
3 | "env": {
4 | "es6": true
5 | }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/override-env-conf.yaml:
--------------------------------------------------------------------------------
1 | extends: "eslint:recommended"
2 | env:
3 | node: true
4 | rules:
5 | no-mixed-requires: 0
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/fileexts/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | rules: {
3 | semi: [2, "always"]
4 | },
5 | root: true
6 | };
7 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/root-true/parent/root/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "rules": {
4 | "semi": [2, "never"]
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/eslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "globals" : {
3 | "test": true
4 | },
5 | "rules": {
6 | "custom-rule": 1
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/personal-config/project-with-config/subfolder/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "subfolder-level-rule": 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/env-webextensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "webextensions": true
4 | },
5 | "rules": {
6 | "no-undef": 2
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/tests/fixtures/globals-webextensions.js:
--------------------------------------------------------------------------------
1 | chrome.browserAction.setBadgeText({text: 'ᕕ( ᐛ)ᕗ'});
2 | opr.sidebarAction.setTitle({title: 'ᕕ( ᐛ)ᕗ'});
3 | browser.tabs.hide();
4 |
--------------------------------------------------------------------------------
/tests/fixtures/max-warnings/six-warnings.js:
--------------------------------------------------------------------------------
1 | var one = "One!";
2 | var two = "Two!";
3 | var three = "Three!";
4 | var four = "Four!";
5 | var five = "Five!";
6 | var six = "Six!";
7 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/array/.eslintrc2:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "comma-dangle": 2
4 | },
5 |
6 | "env": {
7 | "es6": true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "test",
3 | "version": "0.1.1",
4 | "eslintConfig": {
5 | "extends": "./subdir/.eslintrc"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/env-node.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true
4 | },
5 |
6 | "rules": {
7 | "no-console": 0,
8 | "no-undef": 2
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/cwd/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | },
5 |
6 | "rules": {
7 | "quotes": [2, "double"]
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/env-browser.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | },
5 |
6 | "rules": {
7 | "no-alert": 0,
8 | "no-undef": 2
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/my-awesome-config:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | },
5 |
6 | "rules": {
7 | "quotes": [3, "triple"]
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/packagejson/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "",
4 | "eslintConfig": {
5 | "rules": {
6 | "quotes": [1, "single"]
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/parsers/no-line-error.js:
--------------------------------------------------------------------------------
1 | exports.expectedError = "Failed to parse: unexpected token";
2 |
3 | exports.parse = function() {
4 | throw new Error(exports.expectedError);
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/broken/wrong-quotes.js:
--------------------------------------------------------------------------------
1 | // function is necessary to avoid any other errors
2 | function foo(bar) {
3 | "use strict";
4 | return bar;
5 | }
6 |
7 | foo('bar');
8 |
--------------------------------------------------------------------------------
/tests/fixtures/parsers/line-error.js:
--------------------------------------------------------------------------------
1 | exports.expectedError = "Failed to parse: unexpected token";
2 |
3 | exports.parse = function() {
4 | throw new Error("Line 123: " + exports.expectedError);
5 | }
6 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/multi-rulesdirs.json:
--------------------------------------------------------------------------------
1 | {
2 | "globals" : {
3 | "test": true
4 | },
5 | "rules": {
6 | "no-literals": 2,
7 | "no-strings": 2
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | bin/**
2 | build/**
3 | conf/**
4 | coverage/**
5 | docs/**
6 | scripts/**
7 | templates/**
8 | tests/bench/**
9 | tests/fixtures/**
10 | tests/performance/**
11 | tmp/**
12 | test.js
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "",
4 | "eslintConfig": {
5 | "rules": {
6 | "quotes": [1, "single"]
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/comments.json:
--------------------------------------------------------------------------------
1 | {
2 |
3 | /* This is a comment */
4 | "rules": {
5 | "semi": 1,
6 |
7 | // so is this
8 | "strict": 0
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/plugins-without-prefix.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "example"
4 | ],
5 |
6 | "rules": {
7 | "example/example-rule": 1
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | test.js
3 | coverage/
4 | build/
5 | npm-debug.log
6 | .DS_Store
7 | tmp/
8 | .idea
9 | jsdoc/
10 | versions.json
11 | *.iml
12 | .eslintcache
13 | .cache
14 | **/node_modules
15 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/subdir/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "quotes": [1, "single"],
4 | "yoda": 2
5 | },
6 |
7 | "env": {
8 | "browser": true
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/subdir/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "",
4 | "eslintConfig": {
5 | "rules": {
6 | "quotes": [1, "double"]
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/plugins-with-prefix.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "eslint-plugin-example"
4 | ],
5 |
6 | "rules": {
7 | "example/example-rule": 1
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/single-quotes/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | },
5 |
6 | "rules": {
7 | "quotes": [1, "single"],
8 | "no-new": 1
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/deep.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "yoda": 2
4 | },
5 |
6 | "env": {
7 | "browser": true
8 | },
9 |
10 | "extends": "./subdir/subsubdir/deeper.json"
11 | }
12 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/subdir/subsubdir/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "",
4 | "eslintConfig": {
5 | "rules": {
6 | "quotes": [2, "single"]
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/shebang.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /*eslint no-process-exit:0*/
3 |
4 | var cli = require("../lib/cli");
5 | var exitCode = cli.execute(Array.prototype.slice.call(process.argv, 2));
6 | process.exit(exitCode);
7 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/subdir/subsubdir/subsubsubdir/deepest.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "semi": 1,
4 | "valid-jsdoc": 0
5 | },
6 |
7 | "env": {
8 | "browser": true
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/plugins-without-prefix-with-namespace.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "@eslint/example"
4 | ],
5 |
6 | "rules": {
7 | "example/example-rule": 1
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/packagejson/subdir/subsubdir/subsubsubdir/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "",
4 | "eslintConfig": {
5 | "rules": {
6 | "quotes": [2, "double"]
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/config-hierarchy/root-true/parent/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "semi": [2, "always"],
4 | "quotes": [2, "single"]
5 | },
6 | "extends": [
7 | "eslint-config-test"
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/plugins-with-prefix-and-namespace.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "@eslint/eslint-plugin-example"
4 | ],
5 |
6 | "rules": {
7 | "example/example-rule": 1
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/subdir/subsubdir/deeper.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "semi": 2
4 | },
5 |
6 | "env": {
7 | "browser": false
8 | },
9 |
10 | "extends": "./subsubsubdir/deepest.json"
11 | }
12 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/js/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./foo.js",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package2/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "foo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Code
2 |
3 | Please sign our [Contributor License Agreement](http://eslint.org/cla)
4 |
5 | ## Full Documentation
6 |
7 | Our full contribution guidelines can be found at:
8 | http://eslint.org/docs/developer-guide/contributing/
9 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./subdir/.eslintrc",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package3/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "foo/bar",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/dir2/no-literals.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | module.exports = function(context) {
4 |
5 | return {
6 |
7 | "Literal": function(node) {
8 | context.report(node, "Literal!");
9 | }
10 | };
11 | };
12 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/array/.eslintrc1:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "comma-dangle": 1,
4 | "no-console": 2,
5 | "no-empty": 2
6 | },
7 |
8 | "env": {
9 | "browser": true,
10 | "node": true
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package5/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package6/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/array/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | ".eslintrc1",
4 | ".eslintrc2"
5 | ],
6 |
7 | "rules": {
8 | "no-empty": 1
9 | },
10 |
11 | "env": {
12 | "browser": false
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint-config-foo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package2/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/foo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/package4/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "bar-eslint-config-foo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package3/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/foo/bar",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/configurations/processors.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "processor",
4 | "example"
5 | ],
6 |
7 | "rules": {
8 | "no-console": 2,
9 | "no-unused-vars": 2,
10 | "example/example-rule": 1
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/eslint-config-foo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package4/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/eslint-config",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package7/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/eslint-configfoo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/config-extends/scoped-package8/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@scope/bar-eslint-config-foo",
3 |
4 | "rules": {
5 | "quotes": [2, "double"],
6 | "valid-jsdoc": 0
7 | },
8 |
9 | "env": {
10 | "browser": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/dir1/no-strings.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | module.exports = function(context) {
4 |
5 | return {
6 |
7 | "Literal": function(node) {
8 | if (typeof node.value === 'string') {
9 | context.report(node, "String!");
10 | }
11 |
12 | }
13 | };
14 | };
15 |
--------------------------------------------------------------------------------
/lib/api.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Expose out ESLint and CLI to require.
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | module.exports = {
9 | linter: require("./eslint"),
10 | CLIEngine: require("./cli-engine"),
11 | RuleTester: require("./testers/rule-tester"),
12 | SourceCode: require("./util/source-code")
13 | };
14 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "0.10"
4 | - "0.12"
5 | - iojs
6 | - "4"
7 | - "5"
8 | sudo: false
9 | script: "npm test && npm run check-commit && npm run docs"
10 | after_success:
11 | - npm run coveralls
12 | addons:
13 | code_climate:
14 | repo_token: 1945f7420d920a59f1ff8bf8d1a7b60ccd9e2838a692f73a5a74accd8df30146
15 |
--------------------------------------------------------------------------------
/conf/blank-script.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "Program",
3 | "body": [],
4 | "sourceType": "script",
5 | "range": [
6 | 0,
7 | 0
8 | ],
9 | "loc": {
10 | "start": {
11 | "line": 0,
12 | "column": 0
13 | },
14 | "end": {
15 | "line": 0,
16 | "column": 0
17 | }
18 | },
19 | "comments": [],
20 | "tokens": []
21 | }
22 |
--------------------------------------------------------------------------------
/tests/fixtures/rules/custom-rule.js:
--------------------------------------------------------------------------------
1 | module.exports = function(context) {
2 |
3 | "use strict";
4 |
5 | return {
6 | "Identifier": function(node) {
7 | if (node.name === "foo") {
8 | context.report(node, "Identifier cannot be named 'foo'.");
9 | }
10 | }
11 | };
12 |
13 | };
14 |
15 | module.exports.schema = [];
16 |
--------------------------------------------------------------------------------
/tests/fixtures/formatters/simple.js:
--------------------------------------------------------------------------------
1 | /*global module*/
2 | module.exports = function(results) {
3 |
4 | var output = "";
5 |
6 | results.forEach(function(result) {
7 |
8 | var messages = result.messages;
9 | messages.forEach(function(message) {
10 | output += "Problem on line " + (message.line || 0) + "\n";
11 | });
12 |
13 | });
14 |
15 | return output;
16 | };
17 |
--------------------------------------------------------------------------------
/tests/fixtures/formatters/test/simple.js:
--------------------------------------------------------------------------------
1 | /*global module*/
2 | module.exports = function(results) {
3 |
4 | var output = "";
5 |
6 | results.forEach(function(result) {
7 |
8 | var messages = result.messages;
9 | messages.forEach(function(message) {
10 | output += "Problem on line " + (message.line || 0) + "\n";
11 | });
12 |
13 | });
14 |
15 | return output;
16 | };
17 |
--------------------------------------------------------------------------------
/tests/fixtures/processors/custom-processor.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | processors: {
3 | ".txt": {
4 | preprocess: function(text) {
5 | return [text.replace("a()", "b()")];
6 | },
7 | postprocess: function(messages) {
8 | messages[0][0].ruleId = "post-processed";
9 | return messages[0];
10 | }
11 | }
12 | }
13 | };
14 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 4
6 | trim_trailing_whitespace = true
7 | end_of_line = lf
8 | insert_final_newline = true
9 |
10 | [docs/rules/linebreak-style.md]
11 | end_of_line = disabled
12 |
13 | [{docs/rules/{indent.md,no-mixed-spaces-and-tabs.md}]
14 | indent_style = disabled
15 | indent_size = disabled
16 |
17 | [docs/rules/no-trailing-spaces.md]
18 | trim_trailing_whitespace = false
19 |
--------------------------------------------------------------------------------
/ISSUE_CREATE.md:
--------------------------------------------------------------------------------
1 | Thanks for the issue! If you're reporting a bug, please be sure to include:
2 |
3 | 1. The version of ESLint you are using (run `eslint -v`)
4 | 2. What you did (the source code and ESLint configuration)
5 | 3. The actual ESLint output complete with numbers
6 | 4. What you expected to happen instead
7 |
8 | Requesting a new rule? Please see [Proposing a New Rule](http://eslint.org/docs/developer-guide/contributing/new-rules) for instructions.
9 |
--------------------------------------------------------------------------------
/lib/formatters/json.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview JSON reporter
3 | * @author Burak Yigit Kaya aka BYK
4 | * @copyright 2015 Burak Yigit Kaya. All rights reserved.
5 | */
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Public Interface
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(results) {
13 | return JSON.stringify(results);
14 | };
15 |
--------------------------------------------------------------------------------
/docs/rules/no-delete-var.md:
--------------------------------------------------------------------------------
1 | # Disallow Variables Deletion (no-delete-var)
2 |
3 | This rule prevents the use of `delete` operator on variables:
4 |
5 | ```js
6 | /*eslint no-delete-var: 2*/
7 |
8 | var x;
9 | delete x; /*error Variables should not be deleted.*/
10 | ```
11 |
12 | The delete operator will only delete the properties of objects. It cannot "delete" variables or anything else. Using them on variables might lead to unexpected behavior.
13 |
14 | ## Further Reading
15 |
16 | * [Only properties should be deleted](http://jslinterrors.com/only-properties-should-be-deleted/)
17 |
--------------------------------------------------------------------------------
/lib/rules/no-with.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of with statement
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 | "WithStatement": function(node) {
16 | context.report(node, "Unexpected use of 'with' statement.");
17 | }
18 | };
19 |
20 | };
21 |
22 | module.exports.schema = [];
23 |
--------------------------------------------------------------------------------
/lib/rules/no-debugger.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of a debugger statement
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 | "DebuggerStatement": function(node) {
16 | context.report(node, "Unexpected 'debugger' statement.");
17 | }
18 | };
19 |
20 | };
21 |
22 | module.exports.schema = [];
23 |
--------------------------------------------------------------------------------
/lib/rules/no-ternary.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of ternary operators.
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "ConditionalExpression": function(node) {
17 | context.report(node, "Ternary operator used.");
18 | }
19 |
20 | };
21 |
22 | };
23 |
24 | module.exports.schema = [];
25 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-eval.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of eval() statement
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 |
12 | "use strict";
13 |
14 | return {
15 | "CallExpression": function(node) {
16 | if (node.callee.name === "eval") {
17 | context.report(node, "eval sucks.");
18 | }
19 | }
20 | };
21 |
22 | };
23 |
--------------------------------------------------------------------------------
/lib/logging.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Handle logging for Eslint
3 | * @author Gyandeep Singh
4 | * @copyright 2015 Gyandeep Singh. All rights reserved.
5 | */
6 | "use strict";
7 |
8 | /* istanbul ignore next */
9 | module.exports = {
10 | /**
11 | * Cover for console.log
12 | * @returns {void}
13 | */
14 | info: function() {
15 | console.log.apply(console, Array.prototype.slice.call(arguments));
16 | },
17 |
18 | /**
19 | * Cover for console.error
20 | * @returns {void}
21 | */
22 | error: function() {
23 | console.error.apply(console, Array.prototype.slice.call(arguments));
24 | }
25 | };
26 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/modify-ast.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule which modifies AST.
3 | * @author Toru Nagashima
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 | return {
14 | "Identifier": function(node) {
15 | node.name += "!";
16 |
17 | if (node.name === "bar!") {
18 | context.report({message: "error", node: node});
19 | }
20 | }
21 | };
22 | };
23 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-test-filename:
--------------------------------------------------------------------------------
1 | /**
2 | ** @fileoverview Test rule to flag if the filename is missing;
3 | ** @author Stefan Lau
4 | **/
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 | "use strict";
12 |
13 | return {
14 | "Program": function(node) {
15 | if (context.getFilename() === '') {
16 | context.report(node, "Filename test was not defined.");
17 | }
18 | }
19 | };
20 | };
21 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-invalid-args.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** @fileoverview Test rule to flag invalid args
3 | ** @author Mathias Schreck
4 | **/
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 | "use strict";
12 |
13 | var config = context.options[0];
14 |
15 | return {
16 | "Program": function(node) {
17 | if (config === true) {
18 | context.report(node, "Invalid args");
19 | }
20 | }
21 | };
22 | };
23 |
24 |
--------------------------------------------------------------------------------
/lib/rules/no-continue.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of continue statement
3 | * @author Borislav Zhivkov
4 | * @copyright 2015 Borislav Zhivkov. All rights reserved.
5 | */
6 |
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 |
15 | return {
16 | "ContinueStatement": function(node) {
17 | context.report(node, "Unexpected use of continue statement");
18 | }
19 | };
20 |
21 | };
22 |
23 | module.exports.schema = [];
24 |
--------------------------------------------------------------------------------
/docs/rules/space-unary-word-ops.md:
--------------------------------------------------------------------------------
1 | # Require spaces following unary word operators (space-unary-word-ops)
2 |
3 | **Replacement notice**: This rule was removed and has been replaced by the [space-unary-ops](space-unary-ops.md) rule.
4 |
5 | Require spaces following unary word operators.
6 |
7 | ## Rule Details
8 |
9 | The following patterns are considered problems:
10 |
11 | ```js
12 | typeof!a
13 | ```
14 |
15 | ```js
16 | void{a:0}
17 | ```
18 |
19 | ```js
20 | new[a][0]
21 | ```
22 |
23 | ```js
24 | delete(a.b)
25 | ```
26 |
27 | The following patterns are not considered problems:
28 |
29 | ```js
30 | delete a.b
31 | ```
32 |
33 | ```js
34 | new C
35 | ```
36 |
37 | ```js
38 | void 0
39 | ```
40 |
--------------------------------------------------------------------------------
/lib/rules/no-console.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of console object
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "MemberExpression": function(node) {
17 |
18 | if (node.object.name === "console") {
19 | context.report(node, "Unexpected console statement.");
20 | }
21 |
22 | }
23 | };
24 |
25 | };
26 |
27 | module.exports.schema = [];
28 |
--------------------------------------------------------------------------------
/docs/rules/no-empty-label.md:
--------------------------------------------------------------------------------
1 | # No empty labels (no-empty-label)
2 |
3 | Labeled statements are only used in conjunction with labeled break and continue statements. ECMAScript has no goto statement.
4 |
5 |
6 | ## Rule Details
7 |
8 | This error occurs when a label is used to mark a statement that is not an iteration or switch
9 |
10 | The following patterns are considered problems:
11 |
12 | ```js
13 | /*eslint no-empty-label: 2*/
14 |
15 | labeled: /*error Unexpected label "labeled"*/
16 | var x = 10;
17 | ```
18 |
19 | The following patterns are not considered problems:
20 |
21 | ```js
22 | /*eslint no-empty-label: 2*/
23 |
24 | labeled:
25 | for (var i=10; i; i--) {
26 | // ...
27 | }
28 | ```
29 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-test-settings.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** @fileoverview Test rule to flag if the settings var `test` is missing;
3 | ** @author Ilya Volodin
4 | **/
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 | "use strict";
12 |
13 | return {
14 | "Program": function(node) {
15 | if (!context.settings || !context.settings.test) {
16 | context.report(node, "Global settings test was not defined.");
17 | }
18 | }
19 | };
20 | };
21 |
22 |
--------------------------------------------------------------------------------
/lib/rules/no-octal.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when initializing octal literal
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "Literal": function(node) {
17 | if (typeof node.value === "number" && /^0[0-7]/.test(node.raw)) {
18 | context.report(node, "Octal literals should not be used.");
19 | }
20 | }
21 | };
22 |
23 | };
24 |
25 | module.exports.schema = [];
26 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | # AppVeyor file
2 | # http://www.appveyor.com/docs/appveyor-yml
3 |
4 | # Build version format
5 | version: "{build}"
6 |
7 | # What combinations to test
8 | environment:
9 | matrix:
10 | # 2 means latest iojs version in 2.x versions
11 | - nodejs_version: 2
12 | - nodejs_version: 0.12
13 | - nodejs_version: 0.10
14 |
15 | install:
16 | # Get the latest stable version of Node.js or io.js
17 | - ps: Install-Product node $env:nodejs_version
18 | # install modules
19 | - npm install
20 |
21 | build: off
22 |
23 | test_script:
24 | - npm test
25 | - npm run check-commit
26 |
27 | matrix:
28 | fast_finish: true # set this flag to immediately finish build once one of the jobs fails.
29 |
--------------------------------------------------------------------------------
/lib/rules/no-delete-var.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when deleting variables
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "UnaryExpression": function(node) {
17 | if (node.operator === "delete" && node.argument.type === "Identifier") {
18 | context.report(node, "Variables should not be deleted.");
19 | }
20 | }
21 | };
22 |
23 | };
24 |
25 | module.exports.schema = [];
26 |
--------------------------------------------------------------------------------
/lib/rules/no-new-object.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview A rule to disallow calls to the Object constructor
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "NewExpression": function(node) {
17 | if (node.callee.name === "Object") {
18 | context.report(node, "The object literal notation {} is preferrable.");
19 | }
20 | }
21 | };
22 |
23 | };
24 |
25 | module.exports.schema = [];
26 |
--------------------------------------------------------------------------------
/lib/rules/no-var.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to check for the usage of var.
3 | * @author Jamund Ferguson
4 | * @copyright 2014 Jamund Ferguson. All rights reserved.
5 | */
6 |
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 |
15 | return {
16 | "VariableDeclaration": function(node) {
17 | if (node.kind === "var") {
18 | context.report(node, "Unexpected var, use let or const instead.");
19 | }
20 | }
21 |
22 | };
23 |
24 | };
25 |
26 | module.exports.schema = [];
27 |
--------------------------------------------------------------------------------
/lib/rules/no-new-require.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to disallow use of new operator with the `require` function
3 | * @author Wil Moore III
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "NewExpression": function(node) {
17 | if (node.callee.type === "Identifier" && node.callee.name === "require") {
18 | context.report(node, "Unexpected use of new with require.");
19 | }
20 | }
21 | };
22 |
23 | };
24 |
25 | module.exports.schema = [];
26 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-invalid-schema.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** @fileoverview Test rule to flag invalid schemas
3 | ** @author Brandon Mills
4 | **/
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 | "use strict";
12 |
13 | var config = context.options[0];
14 |
15 | return {
16 | "Program": function(node) {
17 | if (config) {
18 | context.report(node, "Expected nothing.");
19 | }
20 | }
21 | };
22 | };
23 |
24 | module.exports.schema = [
25 | {
26 | "enum": []
27 | }
28 | ];
29 |
--------------------------------------------------------------------------------
/docs/rules/no-script-url.md:
--------------------------------------------------------------------------------
1 | # Disallow Script URLs (no-script-url)
2 |
3 | Using `javascript:` URLs is considered by some as a form of `eval`. Code passed in `javascript:` URLs has to be parsed and evaluated by the browser in the same way that `eval` is processed.
4 |
5 | ## Rule Details
6 |
7 | The following patterns are considered problems:
8 |
9 | ```js
10 | /*eslint no-script-url: 2*/
11 |
12 | location.href = "javascript:void(0)"; /*error Script URL is a form of eval.*/
13 | ```
14 |
15 | ## Compatibility
16 |
17 | * **JSHint**: This rule corresponds to `scripturl` rule of JSHint.
18 |
19 | ## Further Reading
20 |
21 | * [What is the matter with script-targeted URLs?](http://stackoverflow.com/questions/13497971/what-is-the-matter-with-script-targeted-urls)
22 |
--------------------------------------------------------------------------------
/lib/rules/no-new.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag statements with function invocation preceded by
3 | * "new" and not part of assignment
4 | * @author Ilya Volodin
5 | */
6 |
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 |
15 | return {
16 |
17 | "ExpressionStatement": function(node) {
18 |
19 | if (node.expression.type === "NewExpression") {
20 | context.report(node, "Do not use 'new' for side effects.");
21 | }
22 | }
23 | };
24 |
25 | };
26 |
27 | module.exports.schema = [];
28 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-schema-violation.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** @fileoverview Test rule to flag schema violations
3 | ** @author Brandon Mills
4 | **/
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 | "use strict";
12 |
13 | var config = context.options[0];
14 |
15 | return {
16 | "Program": function(node) {
17 | if (config && config !== "foo") {
18 | context.report(node, "Expected foo.");
19 | }
20 | }
21 | };
22 | };
23 |
24 | module.exports.schema = [
25 | {
26 | "enum": ["foo"]
27 | }
28 | ];
29 |
--------------------------------------------------------------------------------
/lib/rules/no-eval.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of eval() statement
3 | * @author Nicholas C. Zakas
4 | * @copyright 2015 Mathias Schreck. All rights reserved.
5 | * @copyright 2013 Nicholas C. Zakas. All rights reserved.
6 | */
7 |
8 | "use strict";
9 |
10 | //------------------------------------------------------------------------------
11 | // Rule Definition
12 | //------------------------------------------------------------------------------
13 |
14 | module.exports = function(context) {
15 |
16 | return {
17 | "CallExpression": function(node) {
18 | if (node.callee.name === "eval") {
19 | context.report(node, "eval can be harmful.");
20 | }
21 | }
22 | };
23 |
24 | };
25 |
26 | module.exports.schema = [];
27 |
--------------------------------------------------------------------------------
/lib/rules/no-nested-ternary.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag nested ternary expressions
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 | "ConditionalExpression": function(node) {
16 | if (node.alternate.type === "ConditionalExpression" ||
17 | node.consequent.type === "ConditionalExpression") {
18 | context.report(node, "Do not nest ternary expressions");
19 | }
20 | }
21 | };
22 | };
23 |
24 | module.exports.schema = [];
25 |
--------------------------------------------------------------------------------
/lib/rules/no-negated-in-lhs.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview A rule to disallow negated left operands of the `in` operator
3 | * @author Michael Ficarra
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "BinaryExpression": function(node) {
17 | if (node.operator === "in" && node.left.type === "UnaryExpression" && node.left.operator === "!") {
18 | context.report(node, "The `in` expression's left operand is negated");
19 | }
20 | }
21 | };
22 |
23 | };
24 |
25 | module.exports.schema = [];
26 |
--------------------------------------------------------------------------------
/docs/rules/no-div-regex.md:
--------------------------------------------------------------------------------
1 | # Disallow Regexs That Look Like Division (no-div-regex)
2 |
3 | Require regex literals to escape division operators.
4 |
5 | ```js
6 | function bar() { return /=foo/; }
7 | ```
8 |
9 | ## Rule Details
10 |
11 | This is used to disambiguate the division operator to not confuse users.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-div-regex: 2*/
17 |
18 | function bar() { return /=foo/; } /*error A regular expression literal can be confused with '/='.*/
19 | ```
20 |
21 | The following patterns are not considered problems:
22 |
23 | ```js
24 | /*eslint no-div-regex: 2*/
25 |
26 | function bar() { return /\=foo/; }
27 | ```
28 |
29 | ## Related Rules
30 |
31 | * [no-control-regex](no-control-regex.md)
32 | * [no-regex-spaces](no-regex-spaces.md)
33 |
--------------------------------------------------------------------------------
/docs/rules/require-yield.md:
--------------------------------------------------------------------------------
1 | # Disallow generator functions that do not have `yield` (require-yield)
2 |
3 | This rule generates warnings for generator functions that do not have the `yield` keyword.
4 |
5 | ## Rule details
6 |
7 | The following patterns are considered problems:
8 |
9 | ```js
10 | /*eslint require-yield: 2*/
11 | /*eslint-env es6*/
12 |
13 | function* foo() { /*error This generator function does not have `yield`.*/
14 | return 10;
15 | }
16 | ```
17 |
18 | The following patterns are not considered problems:
19 |
20 | ```js
21 | /*eslint require-yield: 2*/
22 | /*eslint-env es6*/
23 |
24 | function* foo() {
25 | yield 5;
26 | return 10;
27 | }
28 |
29 | function foo() {
30 | return 10;
31 | }
32 |
33 | // This rule does not warn on empty generator functions.
34 | function* foo() { }
35 | ```
36 |
--------------------------------------------------------------------------------
/conf/replacements.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "generator-star": ["generator-star-spacing"],
4 | "global-strict": ["strict"],
5 | "no-comma-dangle": ["comma-dangle"],
6 | "no-empty-class": ["no-empty-character-class"],
7 | "no-extra-strict": ["strict"],
8 | "no-reserved-keys": ["quote-props"],
9 | "no-space-before-semi": ["semi-spacing"],
10 | "no-wrap-func": ["no-extra-parens"],
11 | "space-after-function-name": ["space-before-function-paren"],
12 | "space-before-function-parentheses": ["space-before-function-paren"],
13 | "space-in-brackets": ["object-curly-spacing", "array-bracket-spacing", "computed-property-spacing"],
14 | "space-unary-word-ops": ["space-unary-ops"],
15 | "spaced-line-comment": ["spaced-comment"]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/docs/rules/wrap-regex.md:
--------------------------------------------------------------------------------
1 | # Require Regex Literals to be Wrapped (wrap-regex)
2 |
3 | When a regular expression is used in certain situations, it can end up looking like a division operator. For example:
4 |
5 | ```js
6 | function a() {
7 | return /foo/.test("bar");
8 | }
9 | ```
10 |
11 | ## Rule Details
12 |
13 | This is used to disambiguate the slash operator and facilitates more readable code.
14 |
15 | The following patterns are considered problems:
16 |
17 | ```js
18 | /*eslint wrap-regex: 2*/
19 |
20 | function a() {
21 | return /foo/.test("bar"); /*error Wrap the regexp literal in parens to disambiguate the slash.*/
22 | }
23 | ```
24 |
25 | The following patterns are not considered problems:
26 |
27 | ```js
28 | /*eslint wrap-regex: 2*/
29 |
30 | function a() {
31 | return (/foo/).test("bar");
32 | }
33 | ```
34 |
--------------------------------------------------------------------------------
/lib/rules/no-div-regex.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to check for ambiguous div operator in regexes
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "Literal": function(node) {
17 | var token = context.getFirstToken(node);
18 |
19 | if (token.type === "RegularExpression" && token.value[1] === "=") {
20 | context.report(node, "A regular expression literal can be confused with '/='.");
21 | }
22 | }
23 | };
24 |
25 | };
26 |
27 | module.exports.schema = [];
28 |
--------------------------------------------------------------------------------
/lib/rules/no-new-wrappers.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when using constructor for wrapper objects
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "NewExpression": function(node) {
17 | var wrapperObjects = ["String", "Number", "Boolean", "Math", "JSON"];
18 | if (wrapperObjects.indexOf(node.callee.name) > -1) {
19 | context.report(node, "Do not use {{fn}} as a constructor.", { fn: node.callee.name });
20 | }
21 | }
22 | };
23 |
24 | };
25 |
26 | module.exports.schema = [];
27 |
--------------------------------------------------------------------------------
/docs/rules/no-dupe-args.md:
--------------------------------------------------------------------------------
1 | # No duplicate arguments (no-dupe-args)
2 |
3 | In strict mode you will receive a `SyntaxError` if a function takes multiple arguments with the same name.
4 | Outside of strict mode duplicate arguments will mask the value of the first argument. This rule checks for duplicate
5 | parameter names to help prevent that mistake.
6 |
7 | ## Rule Details
8 |
9 | This rule prevents having duplicate param names.
10 |
11 | For example the following code will cause the rule to warn:
12 |
13 | ```js
14 | /*eslint no-dupe-args: 2*/
15 |
16 | function foo(a, b, a) { /*error Duplicate param 'a'.*/
17 | console.log("which a is it?", a);
18 | }
19 | ```
20 |
21 |
22 | ## When Not To Use It
23 |
24 | If your project uses strict mode this rule may not be needed as unique param names will be automatically enforced.
25 |
--------------------------------------------------------------------------------
/tests/lib/api.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for api.
3 | * @author Gyandeep Singh
4 | * @copyright 2015 Gyandeep Singh. All rights reserved.
5 | * See LICENSE file in root directory for full license.
6 | */
7 |
8 | "use strict";
9 |
10 | var assert = require("chai").assert,
11 | api = require("../../lib/api");
12 |
13 | describe("api", function() {
14 |
15 | it("should have RuleTester exposed", function() {
16 | assert.isFunction(api.RuleTester);
17 | });
18 |
19 | it("should have CLIEngine exposed", function() {
20 | assert.isFunction(api.CLIEngine);
21 | });
22 |
23 | it("should have linter exposed", function() {
24 | assert.isObject(api.linter);
25 | });
26 |
27 | it("should have SourceCode exposed", function() {
28 | assert.isFunction(api.SourceCode);
29 | });
30 | });
31 |
--------------------------------------------------------------------------------
/docs/rules/no-with.md:
--------------------------------------------------------------------------------
1 | # No with Statements (no-with)
2 |
3 | The `with` statement is potentially problematic because it adds members of an object to the current scope, making it impossible to tell what a variable inside the block actually refers to. Additionally, the `with` statement cannot be used in strict mode.
4 |
5 | ## Rule Details
6 |
7 | This rule is aimed at eliminating `with` statements.
8 |
9 | The following patterns are considered problems:
10 |
11 | ```js
12 | /*eslint no-with: 2*/
13 | with (foo) { /*error Unexpected use of 'with' statement.*/
14 | // ...
15 | }
16 | ```
17 |
18 | ## When Not To Use It
19 |
20 | If you intentionally use `with` statements then you can disable this rule.
21 |
22 | ## Further Reading
23 |
24 | * [with Statement Considered Harmful](http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/)
25 |
--------------------------------------------------------------------------------
/lib/rules/use-isnan.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag comparisons to the value NaN
3 | * @author James Allardice
4 | * @copyright 2014 Jordan Harband. All rights reserved.
5 | * @copyright 2013 James Allardice. All rights reserved.
6 | */
7 |
8 | "use strict";
9 |
10 | //------------------------------------------------------------------------------
11 | // Rule Definition
12 | //------------------------------------------------------------------------------
13 |
14 | module.exports = function(context) {
15 |
16 | return {
17 | "BinaryExpression": function(node) {
18 | if (/^(?:[<>]|[!=]=)=?$/.test(node.operator) && (node.left.name === "NaN" || node.right.name === "NaN")) {
19 | context.report(node, "Use the isNaN function to compare with NaN.");
20 | }
21 | }
22 | };
23 |
24 | };
25 |
26 | module.exports.schema = [];
27 |
--------------------------------------------------------------------------------
/lib/rules/no-undefined.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag references to the undefined variable.
3 | * @author Michael Ficarra
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Rule Definition
9 | //------------------------------------------------------------------------------
10 |
11 | module.exports = function(context) {
12 |
13 | return {
14 |
15 | "Identifier": function(node) {
16 | if (node.name === "undefined") {
17 | var parent = context.getAncestors().pop();
18 | if (!parent || parent.type !== "MemberExpression" || node !== parent.property || parent.computed) {
19 | context.report(node, "Unexpected use of undefined.");
20 | }
21 | }
22 | }
23 | };
24 |
25 | };
26 |
27 | module.exports.schema = [];
28 |
--------------------------------------------------------------------------------
/docs/rules/no-spaced-func.md:
--------------------------------------------------------------------------------
1 | # Disallow Spaces in Function Calls (no-spaced-func)
2 |
3 | While it's possible to have whitespace between the name of a function and the parentheses that execute it, such patterns tend to look more like errors.
4 |
5 | **Fixable:** This rule is automatically fixable using the `--fix` flag on the command line.
6 |
7 | ## Rule Details
8 |
9 | This rule does not allow gaps between the function identifier and application.
10 |
11 | ```js
12 | fn ()
13 | ```
14 |
15 | The following patterns are considered problems:
16 |
17 | ```js
18 | /*eslint no-spaced-func: 2*/
19 |
20 | fn () /*error Unexpected space between function name and paren.*/
21 |
22 | fn /*error Unexpected space between function name and paren.*/
23 | ()
24 | ```
25 |
26 | The following patterns are not considered problems:
27 |
28 | ```js
29 | /*eslint no-spaced-func: 2*/
30 |
31 | fn()
32 | ```
33 |
34 |
--------------------------------------------------------------------------------
/lib/rules/no-obj-calls.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of an object property of the global object (Math and JSON) as a function
3 | * @author James Allardice
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 | "CallExpression": function(node) {
16 |
17 | if (node.callee.type === "Identifier") {
18 | var name = node.callee.name;
19 | if (name === "Math" || name === "JSON") {
20 | context.report(node, "'{{name}}' is not a function.", { name: name });
21 | }
22 | }
23 | }
24 | };
25 |
26 | };
27 |
28 | module.exports.schema = [];
29 |
--------------------------------------------------------------------------------
/lib/rules/no-sync.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to check for properties whose identifier ends with the string Sync
3 | * @author Matt DuVall
4 | */
5 |
6 | /* jshint node:true */
7 |
8 | "use strict";
9 |
10 | //------------------------------------------------------------------------------
11 | // Rule Definition
12 | //------------------------------------------------------------------------------
13 |
14 | module.exports = function(context) {
15 |
16 | return {
17 |
18 | "MemberExpression": function(node) {
19 | var propertyName = node.property.name,
20 | syncRegex = /.*Sync$/;
21 |
22 | if (syncRegex.exec(propertyName) !== null) {
23 | context.report(node, "Unexpected sync method: '" + propertyName + "'.");
24 | }
25 | }
26 | };
27 |
28 | };
29 |
30 | module.exports.schema = [];
31 |
--------------------------------------------------------------------------------
/packages/eslint-config-eslint/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "eslint-config-eslint",
3 | "version": "1.0.1",
4 | "author": "Nicholas C. Zakas ",
5 | "description": "Default ESLint configuration for ESLint projects.",
6 | "scripts": {
7 | "test": "node ./index.js",
8 | "prepublish": "npm test"
9 | },
10 | "files": [
11 | "LICENSE",
12 | "README.md",
13 | "index.js",
14 | "default.yml"
15 | ],
16 | "repository": {
17 | "type": "git",
18 | "url": "https://github.com/eslint/eslint"
19 | },
20 | "homepage": "http://eslint.org",
21 | "bugs": "https://github.com/eslint/eslint/issues/",
22 | "dependencies": {
23 | "js-yaml": "^3.4.3"
24 | },
25 | "keywords": [
26 | "eslintconfig",
27 | "eslint-config",
28 | "eslint"
29 | ],
30 | "license": "MIT",
31 | "engines": {
32 | "node": ">=0.10"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/lib/rules/no-proto.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag usage of __proto__ property
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "MemberExpression": function(node) {
17 |
18 | if (node.property &&
19 | (node.property.type === "Identifier" && node.property.name === "__proto__" && !node.computed) ||
20 | (node.property.type === "Literal" && node.property.value === "__proto__")) {
21 | context.report(node, "The '__proto__' property is deprecated.");
22 | }
23 | }
24 | };
25 |
26 | };
27 |
28 | module.exports.schema = [];
29 |
--------------------------------------------------------------------------------
/lib/rules/new-parens.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when using constructor without parentheses
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "NewExpression": function(node) {
17 | var tokens = context.getTokens(node);
18 | var prenticesTokens = tokens.filter(function(token) {
19 | return token.value === "(" || token.value === ")";
20 | });
21 | if (prenticesTokens.length < 2) {
22 | context.report(node, "Missing '()' invoking a constructor");
23 | }
24 | }
25 | };
26 |
27 | };
28 |
29 | module.exports.schema = [];
30 |
--------------------------------------------------------------------------------
/lib/rules/no-empty-label.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when label is not used for a loop or switch
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "LabeledStatement": function(node) {
17 | var type = node.body.type;
18 |
19 | if (type !== "ForStatement" && type !== "WhileStatement" && type !== "DoWhileStatement" && type !== "SwitchStatement" && type !== "ForInStatement" && type !== "ForOfStatement") {
20 | context.report(node, "Unexpected label \"{{l}}\"", {l: node.label.name});
21 | }
22 | }
23 | };
24 |
25 | };
26 |
27 | module.exports.schema = [];
28 |
--------------------------------------------------------------------------------
/lib/rules/no-iterator.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag usage of __iterator__ property
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "MemberExpression": function(node) {
17 |
18 | if (node.property &&
19 | (node.property.type === "Identifier" && node.property.name === "__iterator__" && !node.computed) ||
20 | (node.property.type === "Literal" && node.property.value === "__iterator__")) {
21 | context.report(node, "Reserved name '__iterator__'.");
22 | }
23 | }
24 | };
25 |
26 | };
27 |
28 | module.exports.schema = [];
29 |
--------------------------------------------------------------------------------
/lib/rules/no-process-env.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow the use of process.env()
3 | * @author Vignesh Anand
4 | * @copyright 2014 Vignesh Anand. All rights reserved.
5 | */
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "MemberExpression": function(node) {
17 | var objectName = node.object.name,
18 | propertyName = node.property.name;
19 |
20 | if (objectName === "process" && !node.computed && propertyName && propertyName === "env") {
21 | context.report(node, "Unexpected use of process.env.");
22 | }
23 |
24 | }
25 |
26 | };
27 |
28 | };
29 |
30 | module.exports.schema = [];
31 |
--------------------------------------------------------------------------------
/lib/rules/no-caller.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of arguments.callee and arguments.caller.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "MemberExpression": function(node) {
17 | var objectName = node.object.name,
18 | propertyName = node.property.name;
19 |
20 | if (objectName === "arguments" && !node.computed && propertyName && propertyName.match(/^calle[er]$/)) {
21 | context.report(node, "Avoid arguments.{{property}}.", { property: propertyName });
22 | }
23 |
24 | }
25 | };
26 |
27 | };
28 |
29 | module.exports.schema = [];
30 |
--------------------------------------------------------------------------------
/lib/rules/no-void.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to disallow use of void operator.
3 | * @author Mike Sidorov
4 | * @copyright 2014 Mike Sidorov. All rights reserved.
5 | */
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | //--------------------------------------------------------------------------
15 | // Public
16 | //--------------------------------------------------------------------------
17 |
18 | return {
19 | "UnaryExpression": function(node) {
20 | if (node.operator === "void") {
21 | context.report(node, "Expected 'undefined' and instead saw 'void'.");
22 | }
23 | }
24 | };
25 |
26 | };
27 |
28 | module.exports.schema = [];
29 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-with.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-with rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-with"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-with", rule, {
21 | valid: [
22 | "foo.bar()"
23 | ],
24 | invalid: [
25 | { code: "with(foo) { bar() }", errors: [{ message: "Unexpected use of 'with' statement.", type: "WithStatement"}] }
26 | ]
27 | });
28 |
--------------------------------------------------------------------------------
/docs/rules/no-empty-class.md:
--------------------------------------------------------------------------------
1 | # Disallow Empty Character Classes (no-empty-class)
2 |
3 | **Replacement notice**: This rule was removed in ESLint v1.0 and replaced by the [no-empty-character-class](no-empty-character-class.md) rule.
4 |
5 | Empty character classes in regular expressions do not match anything and can result in code that may not work as intended.
6 |
7 | ```js
8 | var foo = /^abc[]/;
9 | ```
10 |
11 | ## Rule Details
12 |
13 | This rule is aimed at highlighting possible typos and unexpected behavior in regular expressions which may arise from the use of empty character classes.
14 |
15 | The following patterns are considered problems:
16 |
17 | ```js
18 | var foo = /^abc[]/;
19 |
20 | /^abc[]/.test(foo);
21 |
22 | bar.match(/^abc[]/);
23 | ```
24 |
25 | The following patterns are not considered problems:
26 |
27 | ```js
28 | var foo = /^abc/;
29 |
30 | var foo = /^abc[a-z]/;
31 |
32 | var bar = new RegExp("^abc[]");
33 | ```
34 |
--------------------------------------------------------------------------------
/docs/rules/space-return-throw-case.md:
--------------------------------------------------------------------------------
1 | # Require spaces following `return`, `throw`, and `case` (space-return-throw-case)
2 |
3 | Require spaces following `return`, `throw`, and `case`.
4 |
5 | **Fixable:** This rule is automatically fixable using the `--fix` flag on the command line.
6 |
7 | ## Rule Details
8 |
9 | The following patterns are considered problems:
10 |
11 | ```js
12 | /*eslint space-return-throw-case: 2*/
13 |
14 | throw{a:0} /*error Keyword "throw" must be followed by whitespace.*/
15 |
16 | function f(){ return-a; } /*error Keyword "return" must be followed by whitespace.*/
17 |
18 | switch(a){ case'a': break; } /*error Keyword "case" must be followed by whitespace.*/
19 | ```
20 |
21 | The following patterns are not considered problems:
22 |
23 | ```js
24 | /*eslint space-return-throw-case: 2*/
25 |
26 | throw {a: 0};
27 |
28 | function f(){ return -a; }
29 |
30 | switch(a){ case 'a': break; }
31 | ```
32 |
--------------------------------------------------------------------------------
/lib/rules/no-sparse-arrays.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow sparse arrays
3 | * @author Nicholas C. Zakas
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Rule Definition
9 | //------------------------------------------------------------------------------
10 |
11 | module.exports = function(context) {
12 |
13 |
14 | //--------------------------------------------------------------------------
15 | // Public
16 | //--------------------------------------------------------------------------
17 |
18 | return {
19 |
20 | "ArrayExpression": function(node) {
21 |
22 | var emptySpot = node.elements.indexOf(null) > -1;
23 |
24 | if (emptySpot) {
25 | context.report(node, "Unexpected comma in middle of array.");
26 | }
27 | }
28 |
29 | };
30 |
31 | };
32 |
33 | module.exports.schema = [];
34 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-var.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to remove var statement
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 |
12 | "use strict";
13 |
14 |
15 | var sourceCode = context.getSourceCode();
16 |
17 | return {
18 |
19 | "VariableDeclaration": function(node) {
20 | if (node.kind === "var") {
21 | context.report({
22 | node: node,
23 | message: "Bad var.",
24 | fix: function(fixer) {
25 | return fixer.remove(sourceCode.getFirstToken(node));
26 | }
27 | })
28 | }
29 | }
30 | };
31 |
32 | };
33 |
--------------------------------------------------------------------------------
/lib/rules/no-script-url.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when using javascript: urls
3 | * @author Ilya Volodin
4 | */
5 | /* jshint scripturl: true */
6 | /* eslint no-script-url: 0 */
7 |
8 | "use strict";
9 |
10 | //------------------------------------------------------------------------------
11 | // Rule Definition
12 | //------------------------------------------------------------------------------
13 |
14 | module.exports = function(context) {
15 |
16 | return {
17 |
18 | "Literal": function(node) {
19 |
20 | var value;
21 |
22 | if (node.value && typeof node.value === "string") {
23 | value = node.value.toLowerCase();
24 |
25 | if (value.indexOf("javascript:") === 0) {
26 | context.report(node, "Script URL is a form of eval.");
27 | }
28 | }
29 | }
30 | };
31 |
32 | };
33 |
34 | module.exports.schema = [];
35 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-delete-var.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-delete-var rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-delete-var"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-delete-var", rule, {
21 | valid: [
22 | "delete x.prop;"
23 | ],
24 | invalid: [
25 | { code: "delete x", errors: [{ message: "Variables should not be deleted.", type: "UnaryExpression"}] }
26 | ]
27 | });
28 |
--------------------------------------------------------------------------------
/lib/rules/no-eq-null.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag comparisons to null without a type-checking
3 | * operator.
4 | * @author Ian Christian Myers
5 | */
6 |
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 |
15 | return {
16 |
17 | "BinaryExpression": function(node) {
18 | var badOperator = node.operator === "==" || node.operator === "!=";
19 |
20 | if (node.right.type === "Literal" && node.right.raw === "null" && badOperator ||
21 | node.left.type === "Literal" && node.left.raw === "null" && badOperator) {
22 | context.report(node, "Use ‘===’ to compare with ‘null’.");
23 | }
24 | }
25 | };
26 |
27 | };
28 |
29 | module.exports.schema = [];
30 |
--------------------------------------------------------------------------------
/tests/tests.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Browser smoke test
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/docs/rules/no-octal-escape.md:
--------------------------------------------------------------------------------
1 | # Disallow Octal Escapes (no-octal-escape)
2 |
3 | As of version 5 of the ECMAScript specification, octal escape sequences are a deprecated feature and should not be used. It is recommended that Unicode escapes be used instead.
4 |
5 | ```js
6 | var foo = "Copyright \251";
7 | ```
8 |
9 | ## Rule Details
10 |
11 | The rule is aimed at preventing the use of a deprecated JavaScript feature, the use of octal escape sequences. As such it will warn whenever an octal escape sequence is found in a string literal.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-octal-escape: 2*/
17 |
18 | var foo = "Copyright \251"; /*error Don't use octal: '\251'. Use '\u....' instead.*/
19 | ```
20 |
21 | The following patterns are not considered problems:
22 |
23 | ```js
24 | /*eslint no-octal-escape: 2*/
25 |
26 | var foo = "Copyright \u00A9"; // unicode
27 |
28 | var foo = "Copyright \xA9"; // hexadecimal
29 | ```
30 |
--------------------------------------------------------------------------------
/lib/rules/no-undef-init.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when initializing to undefined
3 | * @author Ilya Volodin
4 | * @copyright 2013 Ilya Volodin. All rights reserved.
5 | * See LICENSE in root directory for full license.
6 | */
7 |
8 | "use strict";
9 |
10 | //------------------------------------------------------------------------------
11 | // Rule Definition
12 | //------------------------------------------------------------------------------
13 |
14 | module.exports = function(context) {
15 |
16 | return {
17 |
18 | "VariableDeclarator": function(node) {
19 | var name = node.id.name,
20 | init = node.init && node.init.name;
21 |
22 | if (init === "undefined" && node.parent.kind !== "const") {
23 | context.report(node, "It's not necessary to initialize '{{name}}' to undefined.", { name: name });
24 | }
25 | }
26 | };
27 |
28 | };
29 |
30 | module.exports.schema = [];
31 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-debugger.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-debugger rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-debugger"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-debugger", rule, {
21 | valid: [
22 | "var test = { debugger: 1 }; test.debugger;"
23 | ],
24 | invalid: [
25 | { code: "debugger", errors: [{ message: "Unexpected 'debugger' statement.", type: "DebuggerStatement"}] }
26 | ]
27 | });
28 |
--------------------------------------------------------------------------------
/docs/rules/no-label-var.md:
--------------------------------------------------------------------------------
1 | # Disallow Labels That Are Variables Names (no-label-var)
2 |
3 | ## Rule Details
4 |
5 | This rule aims to create clearer code by disallowing the bad practice of creating a label that shares a name with a variable that is in scope.
6 |
7 | The following patterns are considered problems:
8 |
9 | ```js
10 | /*eslint no-label-var: 2*/
11 |
12 | var x = foo;
13 | function bar() {
14 | x: /*error Found identifier with same name as label.*/
15 | for (;;) {
16 | break x;
17 | }
18 | }
19 | ```
20 |
21 | The following patterns are not considered problems:
22 |
23 | ```js
24 | /*eslint no-label-var: 2*/
25 |
26 | // The variable that has the same name as the label is not in scope.
27 |
28 | function foo() {
29 | var q = t;
30 | }
31 |
32 | function bar() {
33 | q:
34 | for(;;) {
35 | break q;
36 | }
37 | }
38 | ```
39 |
40 | ## Further Reading
41 |
42 | * ['{a}' is a statement label](http://jslinterrors.com/a-is-a-statement-label/)
43 |
--------------------------------------------------------------------------------
/docs/rules/new-parens.md:
--------------------------------------------------------------------------------
1 | # Require Parens for Constructors (new-parens)
2 |
3 | JavaScript allows the omission of parentheses when invoking a function via the `new` keyword and the constructor has no arguments. However, some coders believe that omitting the parentheses is inconsistent with the rest of the language and thus makes code less clear.
4 |
5 | ```js
6 | var person = new Person;
7 | ```
8 |
9 | ## Rule Details
10 |
11 | This rule is aimed at highlighting a lack of convention and increasing code clarity by requiring the use of parentheses when invoking a constructor via the `new` keyword. As such, it will warn when these parentheses are omitted.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint new-parens: 2*/
17 |
18 | var person = new Person; /*error Missing '()' invoking a constructor*/
19 | ```
20 |
21 | The following patterns are not considered problems:
22 |
23 | ```js
24 | /*eslint new-parens: 2*/
25 |
26 | var person = new Person();
27 | ```
28 |
--------------------------------------------------------------------------------
/lib/rules/no-empty-pattern.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to disallow an empty pattern
3 | * @author Alberto Rodríguez
4 | * @copyright 2015 Alberto Rodríguez. All rights reserved.
5 | * See LICENSE file in root directory for full license.
6 | */
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 | return {
15 | "ObjectPattern": function(node) {
16 | if (node.properties.length === 0) {
17 | context.report(node, "Unexpected empty object pattern.");
18 | }
19 | },
20 | "ArrayPattern": function(node) {
21 | if (node.elements.length === 0) {
22 | context.report(node, "Unexpected empty array pattern.");
23 | }
24 | }
25 | };
26 | };
27 |
28 | module.exports.schema = [];
29 |
--------------------------------------------------------------------------------
/tests/bench/xform-rules.js:
--------------------------------------------------------------------------------
1 | module.exports = transform;
2 |
3 | var fs = require("fs"),
4 | path = require("path"),
5 | through = require("through");
6 |
7 | var target = path.resolve(__dirname, "..", "..", "lib", "load-rules.js");
8 |
9 |
10 | function transform(filename) {
11 | if(filename === target) {
12 | return through(noop, inject);
13 | }
14 |
15 | return through();
16 | }
17 |
18 | function noop() {
19 |
20 | }
21 |
22 | function inject() {
23 | var output = "module.exports = function() {\n";
24 | output += " var rules = Object.create(null);\n";
25 |
26 | fs.readdirSync(path.resolve(__dirname, "..", "..", "lib", "rules")).forEach(function(filename) {
27 | var basename = path.basename(filename, ".js");
28 | output += " rules[\"" + basename + "\"] = require(\"./rules/" + basename + "\");\n";
29 | });
30 |
31 | output += "\n return rules;\n};";
32 |
33 | this.queue(output);
34 | this.queue(null);
35 | }
36 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/no-test-global.js:
--------------------------------------------------------------------------------
1 | /**
2 | ** @fileoverview Test rule to flag if the global var `test` is missing;
3 | ** @author Mathias Schreck
4 | **/
5 |
6 | //------------------------------------------------------------------------------
7 | // Rule Definition
8 | //------------------------------------------------------------------------------
9 |
10 | module.exports = function(context) {
11 | "use strict";
12 |
13 | return {
14 | "Program": function(node) {
15 | var globals = context.getScope().variables.map(function (variable) {
16 | return variable.name;
17 | });
18 |
19 | if (globals.indexOf("test") === -1) {
20 | context.report(node, "Global variable test was not defined.");
21 | }
22 | if (globals.indexOf("foo") !== -1) {
23 | context.report(node, "Global variable foo should not be used.");
24 | }
25 | }
26 | };
27 | };
28 |
29 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-new.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-new rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-new"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-new", rule, {
21 | valid: [
22 | "var a = new Date()",
23 | "var a; if (a === new Date()) { a = false; }"
24 | ],
25 | invalid: [
26 | { code: "new Date()", errors: [{ message: "Do not use 'new' for side effects.", type: "ExpressionStatement"}] }
27 | ]
28 | });
29 |
--------------------------------------------------------------------------------
/docs/rules/no-multi-str.md:
--------------------------------------------------------------------------------
1 | # Disallow Multiline Strings (no-multi-str)
2 |
3 | It's possible to create multiline strings in JavaScript by using a slash before a newline, such as:
4 |
5 | ```js
6 | var x = "Line 1 \
7 | Line 2";
8 | ```
9 |
10 | Some consider this to be a bad practice as it was an undocumented feature of JavaScript that was only formalized later.
11 |
12 | ## Rule Details
13 |
14 | This rule is aimed at preventing the use of multiline strings.
15 |
16 | The following generates a warning:
17 |
18 | ```js
19 | /*eslint no-multi-str: 2*/
20 |
21 | /*error Multiline support is limited to browsers supporting ES5 only.*/ var x = "Line 1 \
22 | Line 2";
23 | ```
24 |
25 | The following does not generate a warning:
26 |
27 | ```js
28 | /*eslint no-multi-str: 2*/
29 |
30 | var x = "Line 1\n" +
31 | "Line 2";
32 | ```
33 |
34 |
35 |
36 | ## Further Reading
37 |
38 | * [Bad escapement of EOL](http://jslinterrors.com/bad-escapement-of-eol-use-option-multistr-if-needed/)
39 |
--------------------------------------------------------------------------------
/tests/lib/rules/new-parens.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for new-parens rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/new-parens"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("new-parens", rule, {
21 | valid: [
22 | "var a = new Date();",
23 | "var a = new Date(function() {});"
24 | ],
25 | invalid: [
26 | { code: "var a = new Date;", errors: [{ message: "Missing '()' invoking a constructor", type: "NewExpression"}] }
27 | ]
28 | });
29 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-negated-in-lhs.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for the no-negated-in-lhs rule
3 | * @author Michael Ficarra
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-negated-in-lhs"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-negated-in-lhs", rule, {
21 | valid: [
22 | "a in b",
23 | "!(a in b)"
24 | ],
25 | invalid: [
26 | { code: "!a in b", errors: [{ message: "The `in` expression's left operand is negated", type: "BinaryExpression"}] }
27 | ]
28 | });
29 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-regex-spaces.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for regex-spaces rule.
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-regex-spaces"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | var ruleTester = new RuleTester();
16 | ruleTester.run("no-regex-spaces", rule, {
17 | valid: [
18 | "var foo = /bar {3}baz/;",
19 | "var foo = /bar\t\t\tbaz/;"
20 | ],
21 |
22 | invalid: [
23 | {
24 | code: "var foo = /bar baz/;",
25 | errors: [
26 | {
27 | message: "Spaces are hard to count. Use {4}.",
28 | type: "Literal"
29 | }
30 | ]
31 | }
32 | ]
33 | });
34 |
--------------------------------------------------------------------------------
/lib/rules/no-floating-decimal.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of a leading/trailing decimal point in a numeric literal
3 | * @author James Allardice
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 | "Literal": function(node) {
16 |
17 | if (typeof node.value === "number") {
18 | if (node.raw.indexOf(".") === 0) {
19 | context.report(node, "A leading decimal point can be confused with a dot.");
20 | }
21 | if (node.raw.indexOf(".") === node.raw.length - 1) {
22 | context.report(node, "A trailing decimal point can be confused with a dot.");
23 | }
24 | }
25 | }
26 | };
27 |
28 | };
29 |
30 | module.exports.schema = [];
31 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-new-object.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for the no-new-object rule
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-new-object"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-new-object", rule, {
21 | valid: [
22 | "var foo = new foo.Object()"
23 | ],
24 | invalid: [
25 | { code: "var foo = new Object()", errors: [{ message: "The object literal notation {} is preferrable.", type: "NewExpression"}] }
26 | ]
27 | });
28 |
--------------------------------------------------------------------------------
/docs/rules/no-space-before-semi.md:
--------------------------------------------------------------------------------
1 | # Disallow Spaces Before Semicolon (no-space-before-semi)
2 |
3 | **Replacement notice**: This rule was removed in ESLint v1.0 and replaced by the [semi-spacing](semi-spacing.md) rule.
4 |
5 | JavaScript allows for placing unnecessary spaces between an expression and the closing semicolon.
6 |
7 | Space issues can also cause code to look inconsistent and harder to read.
8 |
9 | ```js
10 | var thing = function () {
11 | var test = 12 ;
12 | } ;
13 | ```
14 |
15 | ## Rule Details
16 |
17 | This rule prevents the use of spaces before a semicolon in expressions.
18 |
19 | The following patterns are considered problems:
20 |
21 | ```js
22 | var foo = "bar" ;
23 |
24 | var foo = function() {} ;
25 |
26 | var foo = function() {
27 | } ;
28 |
29 | var foo = 1 + 2 ;
30 | ```
31 |
32 | The following patterns are not considered problems:
33 |
34 | ```js
35 | ;(function(){}());
36 |
37 | var foo = "bar";
38 | ```
39 |
40 | ## Related Rules
41 |
42 | * [semi](semi.md)
43 | * [no-extra-semi](no-extra-semi.md)
44 |
--------------------------------------------------------------------------------
/tests/bench/bench.js:
--------------------------------------------------------------------------------
1 | var eslint = require("../../lib/eslint"),
2 | fs = require("fs");
3 |
4 | var config = require("../../conf/eslint.json");
5 |
6 | var large = fs.readFileSync(__dirname + "/large.js", "utf8"),
7 | medium = fs.readFileSync(__dirname + "/medium.js", "utf8"),
8 | small = fs.readFileSync(__dirname + "/small.js", "utf8");
9 |
10 | var runs = {
11 | large: large,
12 | medium: medium,
13 | small: small
14 | };
15 |
16 | benchmark.runs = runs;
17 | benchmark(Boolean, 1);
18 |
19 | function benchmark(grep, times) {
20 | console.profile("all");
21 | for(var key in runs) {
22 | if(grep(key)) {
23 | console.time(key);
24 | console.profile(key);
25 | run(runs[key], times);
26 | console.profileEnd(key);
27 | console.timeEnd(key);
28 | }
29 | }
30 | console.profileEnd("all");
31 | }
32 |
33 | function run(content, times) {
34 | while(times--) {
35 | eslint.reset();
36 | eslint.verify(content, config);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/docs/rules/no-empty-character-class.md:
--------------------------------------------------------------------------------
1 | # Disallow Empty Character Classes (no-empty-character-class)
2 |
3 | Empty character classes in regular expressions do not match anything and can result in code that may not work as intended.
4 |
5 | ```js
6 | var foo = /^abc[]/;
7 | ```
8 |
9 | ## Rule Details
10 |
11 | This rule is aimed at highlighting possible typos and unexpected behavior in regular expressions which may arise from the use of empty character classes.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-empty-character-class: 2*/
17 |
18 | var foo = /^abc[]/; /*error Empty class.*/
19 |
20 | /^abc[]/.test(foo); /*error Empty class.*/
21 |
22 | bar.match(/^abc[]/); /*error Empty class.*/
23 | ```
24 |
25 | The following patterns are not considered problems:
26 |
27 | ```js
28 | /*eslint no-empty-character-class: 2*/
29 |
30 | var foo = /^abc/;
31 |
32 | var foo = /^abc[a-z]/;
33 |
34 | var bar = new RegExp("^abc[]");
35 | ```
36 |
37 | ## Related Rules
38 |
39 | * [no-empty-class](no-empty-class.md) (removed)
40 |
--------------------------------------------------------------------------------
/lib/rules/no-process-exit.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow the use of process.exit()
3 | * @author Nicholas C. Zakas
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Rule Definition
9 | //------------------------------------------------------------------------------
10 |
11 | module.exports = function(context) {
12 |
13 | //--------------------------------------------------------------------------
14 | // Public
15 | //--------------------------------------------------------------------------
16 |
17 | return {
18 |
19 | "CallExpression": function(node) {
20 | var callee = node.callee;
21 |
22 | if (callee.type === "MemberExpression" && callee.object.name === "process" &&
23 | callee.property.name === "exit"
24 | ) {
25 | context.report(node, "Don't use process.exit(); throw an error instead.");
26 | }
27 | }
28 |
29 | };
30 |
31 | };
32 |
33 | module.exports.schema = [];
34 |
--------------------------------------------------------------------------------
/scripts/bundle.sh:
--------------------------------------------------------------------------------
1 | outputDir=build
2 | bundleFile=$outputDir/eslint-min.js
3 |
4 | # generate a module that lists all rules in the rules directory
5 | rulesFile=lib/rules/index.js
6 | echo 'module.exports = function() {' > $rulesFile
7 | echo ' var rules = Object.create(null);' >> $rulesFile
8 | for ruleFile in lib/rules/*.js; do
9 | if [ $ruleFile '!=' $rulesFile ]; then
10 | ruleFile=${ruleFile#lib/rules/}
11 | ruleName=${ruleFile%.js}
12 | echo " rules[\"$ruleName\"] = require(\"./$ruleFile\");" >> $rulesFile
13 | fi
14 | done
15 | echo ' return rules;' >> $rulesFile
16 | echo '};' >> $rulesFile
17 |
18 | if [ ! -d $outputDir ]; then
19 | mkdir $outputDir
20 | fi
21 |
22 | # bundle, using our generated rule module instead of dynamic loader in /lib/load-rules.js
23 | node_modules/.bin/cjsify \
24 | --minify \
25 | --export eslint \
26 | --inline-sources --source-map $bundleFile.map \
27 | --alias /lib/load-rules.js:/lib/rules/index.js \
28 | lib/eslint.js > $bundleFile
29 |
30 | # clean up
31 | rm $rulesFile
32 |
--------------------------------------------------------------------------------
/lib/rules/no-lonely-if.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to disallow if as the only statmenet in an else block
3 | * @author Brandon Mills
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Rule Definition
9 | //------------------------------------------------------------------------------
10 |
11 | module.exports = function(context) {
12 |
13 | return {
14 | "IfStatement": function(node) {
15 | var ancestors = context.getAncestors(),
16 | parent = ancestors.pop(),
17 | grandparent = ancestors.pop();
18 |
19 | if (parent && parent.type === "BlockStatement" &&
20 | parent.body.length === 1 && grandparent &&
21 | grandparent.type === "IfStatement" &&
22 | parent === grandparent.alternate) {
23 | context.report(node, "Unexpected if as the only statement in an else block.");
24 | }
25 | }
26 | };
27 |
28 | };
29 |
30 | module.exports.schema = [];
31 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-obj-calls.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-obj-calls rule.
3 | * @author James Allardice
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-obj-calls"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-obj-calls", rule, {
21 | valid: [
22 | "var x = Math.random();"
23 | ],
24 | invalid: [
25 | { code: "var x = Math();", errors: [{ message: "'Math' is not a function.", type: "CallExpression"}] },
26 | { code: "var x = JSON();", errors: [{ message: "'JSON' is not a function.", type: "CallExpression"}] }
27 | ]
28 | });
29 |
--------------------------------------------------------------------------------
/lib/rules/no-self-compare.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag comparison where left part is the same as the right
3 | * part.
4 | * @author Ilya Volodin
5 | */
6 |
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 |
15 | return {
16 |
17 | "BinaryExpression": function(node) {
18 | var operators = ["===", "==", "!==", "!=", ">", "<", ">=", "<="];
19 | if (operators.indexOf(node.operator) > -1 &&
20 | (node.left.type === "Identifier" && node.right.type === "Identifier" && node.left.name === node.right.name ||
21 | node.left.type === "Literal" && node.right.type === "Literal" && node.left.value === node.right.value)) {
22 | context.report(node, "Comparing to itself is potentially pointless.");
23 | }
24 | }
25 | };
26 |
27 | };
28 |
29 | module.exports.schema = [];
30 |
--------------------------------------------------------------------------------
/lib/rules/global-require.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule for disallowing require() outside of the top-level module context
3 | * @author Jamund Ferguson
4 | * @copyright 2015 Jamund Ferguson. All rights reserved.
5 | */
6 |
7 | "use strict";
8 |
9 | var ACCEPTABLE_PARENTS = [
10 | "AssignmentExpression",
11 | "VariableDeclarator",
12 | "MemberExpression",
13 | "ExpressionStatement",
14 | "CallExpression",
15 | "ConditionalExpression",
16 | "Program",
17 | "VariableDeclaration"
18 | ];
19 |
20 | module.exports = function(context) {
21 | return {
22 | "CallExpression": function(node) {
23 | if (node.callee.name === "require") {
24 | var isGoodRequire = context.getAncestors().every(function(parent) {
25 | return ACCEPTABLE_PARENTS.indexOf(parent.type) > -1;
26 | });
27 | if (!isGoodRequire) {
28 | context.report(node, "Unexpected require().");
29 | }
30 | }
31 | }
32 | };
33 | };
34 |
35 | module.exports.schema = [];
36 |
--------------------------------------------------------------------------------
/lib/rules/guard-for-in.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag for-in loops without if statements inside
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "ForInStatement": function(node) {
17 |
18 | /*
19 | * If the for-in statement has {}, then the real body is the body
20 | * of the BlockStatement. Otherwise, just use body as provided.
21 | */
22 | var body = node.body.type === "BlockStatement" ? node.body.body[0] : node.body;
23 |
24 | if (body && body.type !== "IfStatement") {
25 | context.report(node, "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.");
26 | }
27 | }
28 | };
29 |
30 | };
31 |
32 | module.exports.schema = [];
33 |
--------------------------------------------------------------------------------
/lib/rules/no-duplicate-case.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to disallow a duplicate case label.
3 | * @author Dieter Oberkofler
4 | * @author Burak Yigit Kaya
5 | * @copyright 2015 Dieter Oberkofler. All rights reserved.
6 | * @copyright 2015 Burak Yigit Kaya. All rights reserved.
7 | */
8 |
9 | "use strict";
10 |
11 | //------------------------------------------------------------------------------
12 | // Rule Definition
13 | //------------------------------------------------------------------------------
14 |
15 | module.exports = function(context) {
16 |
17 | return {
18 | "SwitchStatement": function(node) {
19 | var mapping = {};
20 |
21 | node.cases.forEach(function(switchCase) {
22 | var key = context.getSource(switchCase.test);
23 | if (mapping[key]) {
24 | context.report(switchCase, "Duplicate case label.");
25 | } else {
26 | mapping[key] = switchCase;
27 | }
28 | });
29 | }
30 | };
31 | };
32 |
33 | module.exports.schema = [];
34 |
--------------------------------------------------------------------------------
/docs/rules/no-eq-null.md:
--------------------------------------------------------------------------------
1 | # Disallow Null Comparisons (no-eq-null)
2 |
3 | Comparing to `null` without a type-checking operator (`==` or `!=`), can have unintended results as the comparison will evaluate to true when comparing to not just a `null`, but also an `undefined` value.
4 |
5 | ```js
6 | if (foo == null) {
7 | bar();
8 | }
9 | ```
10 |
11 | ## Rule Details
12 |
13 | The `no-eq-null` rule aims reduce potential bug and unwanted behavior by ensuring that comparisons to `null` only match `null`, and not also `undefined`. As such it will flag comparisons to null when using `==` and `!=`.
14 |
15 | The following patterns are considered problems:
16 |
17 | ```js
18 | /*eslint no-eq-null: 2*/
19 |
20 | if (foo == null) { /*error Use ‘===’ to compare with ‘null’.*/
21 | bar();
22 | }
23 |
24 | while (qux != null) { /*error Use ‘===’ to compare with ‘null’.*/
25 | baz();
26 | }
27 | ```
28 |
29 | The following patterns are considered okay:
30 |
31 | ```js
32 | /*eslint no-eq-null: 2*/
33 |
34 | if (foo === null) {
35 | bar();
36 | }
37 |
38 | while (qux !== null) {
39 | baz();
40 | }
41 | ```
42 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-div-regex.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-div-regex rule.
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-div-regex"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-div-regex", rule, {
21 | valid: [
22 | "var f = function() { return /foo/ig.test('bar'); };",
23 | "var f = function() { return /\\=foo/; };"
24 | ],
25 | invalid: [
26 | { code: "var f = function() { return /=foo/; };", errors: [{ message: "A regular expression literal can be confused with '/='.", type: "Literal"}] }
27 | ]
28 | });
29 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-sync.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-sync.
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-sync"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-sync", rule, {
21 | valid: [
22 | "var foo = fs.foo.foo();"
23 | ],
24 | invalid: [
25 | { code: "var foo = fs.fooSync();", errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression"}] },
26 | { code: "var foo = fs.fooSync;", errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression"}] }
27 | ]
28 | });
29 |
--------------------------------------------------------------------------------
/docs/rules/no-control-regex.md:
--------------------------------------------------------------------------------
1 | # Disallow Controls Characters in Regular Expressions (no-control-regex)
2 |
3 | Control characters are special, invisible characters in the ASCII range 0-31. These characters are rarely used in JavaScript strings so a regular expression containing these characters is most likely a mistake.
4 |
5 | ## Rule Details
6 |
7 | This rule is aimed at ensuring all regular expressions don't use control characters.
8 |
9 |
10 | The following patterns are considered problems:
11 |
12 | ```js
13 | /*eslint no-control-regex: 2*/
14 |
15 | var pattern1 = /\\x1f/;
16 | var pattern2 = new RegExp("\x1f"); /*error Unexpected control character in regular expression.*/
17 | ```
18 |
19 | The following patterns do not cause a warning:
20 |
21 | ```js
22 | /*eslint no-control-regex: 2*/
23 |
24 | var pattern1 = /\\x20/;
25 | var pattern2 = new RegExp("\x20");
26 | ```
27 |
28 | ## When Not To Use It
29 |
30 | If you need to use control character pattern matching, then you should turn this rule off.
31 |
32 | ## Related Rules
33 |
34 | * [no-div-regex](no-div-regex.md)
35 | * [no-regex-spaces](no-regex-spaces.md)
36 |
37 |
--------------------------------------------------------------------------------
/lib/rules/no-array-constructor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow construction of dense arrays using the Array constructor
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | /**
15 | * Disallow construction of dense arrays using the Array constructor
16 | * @param {ASTNode} node node to evaluate
17 | * @returns {void}
18 | * @private
19 | */
20 | function check(node) {
21 | if (
22 | node.arguments.length !== 1 &&
23 | node.callee.type === "Identifier" &&
24 | node.callee.name === "Array"
25 | ) {
26 | context.report(node, "The array literal notation [] is preferrable.");
27 | }
28 | }
29 |
30 | return {
31 | "CallExpression": check,
32 | "NewExpression": check
33 | };
34 |
35 | };
36 |
37 | module.exports.schema = [];
38 |
--------------------------------------------------------------------------------
/docs/rules/no-native-reassign.md:
--------------------------------------------------------------------------------
1 | # Disallow Reassignment of Native Objects (no-native-reassign)
2 |
3 | Reports an error when they encounter an attempt to assign a value to built-in native object.
4 |
5 | ```js
6 | String = "hello world";
7 | ```
8 |
9 | ## Rule Details
10 |
11 | The native objects reported by this rule are the `builtin` variables from [globals](https://github.com/sindresorhus/globals/).
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-native-reassign: 2*/
17 |
18 | String = new Object(); /*error String is a read-only native object.*/
19 | ```
20 |
21 | ## Options
22 |
23 | This rule accepts an `exceptions` option, which can be used to specify a list of builtins for which reassignments will be allowed:
24 |
25 | ```json
26 | {
27 | "rules": {
28 | "no-native-reassign": [2, {"exceptions": ["Object"]}]
29 | }
30 | }
31 | ```
32 |
33 | ## When Not To Use It
34 |
35 | If you are trying to override one of the native objects.
36 |
37 | ## Related Rules
38 |
39 | * [no-extend-native](no-extend-native.md)
40 | * [no-redeclare](no-redeclare.md)
41 | * [no-shadow](no-shadow.md)
42 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-proto.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-proto rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-proto"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-proto", rule, {
21 | valid: [
22 | "var a = test[__proto__];",
23 | "var __proto__ = null;"
24 | ],
25 | invalid: [
26 | { code: "var a = test.__proto__;", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression"}] },
27 | { code: "var a = test['__proto__'];", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/docs/rules/no-new.md:
--------------------------------------------------------------------------------
1 | # Disallow new For Side Effects (no-new)
2 |
3 | The goal of using `new` with a constructor is typically to create an object of a particular type and store that object in a variable, such as:
4 |
5 | ```js
6 | var person = new Person();
7 | ```
8 |
9 | It's less common to use `new` and not store the result, such as:
10 |
11 | ```js
12 | new Person();
13 | ```
14 |
15 | In this case, the created object is thrown away because its reference isn't stored anywhere, and in many cases, this means that the constructor should be replaced with a function that doesn't require `new` to be used.
16 |
17 | ## Rule Details
18 |
19 | This rule is aimed at maintaining consistency and convention by disallowing constructor calls using the `new` keyword that do not assign the resulting object to a variable.
20 |
21 | The following patterns are considered problems:
22 |
23 | ```js
24 | /*eslint no-new: 2*/
25 |
26 | new Thing(); /*error Do not use 'new' for side effects.*/
27 | ```
28 |
29 | The following patterns are not considered problems:
30 |
31 | ```js
32 | /*eslint no-new: 2*/
33 |
34 | var thing = new Thing();
35 |
36 | Thing();
37 | ```
38 |
--------------------------------------------------------------------------------
/docs/rules/no-self-compare.md:
--------------------------------------------------------------------------------
1 | # Disallow Self Compare (no-self-compare)
2 |
3 | Comparing a variable against itself is usually an error, either an typo or refactoring error. It is confusing to the reader and may potentially introduce a runtime error.
4 |
5 | The only time you would compare a variable against itself is when you are testing for `NaN`. However, it is far more appropriate to use `typeof x === 'number' && isNaN(x)` or the [Number.isNaN ES2015 function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) for that use case rather than leaving the reader of the code to determine the intent of self comparison.
6 |
7 | ## Rule Details
8 |
9 | This error is raised to highlight a potentially confusing and potentially pointless piece of code. There are almost no situations in which you would need to compare something to itself.
10 |
11 | ```js
12 | /*eslint no-self-compare: 2*/
13 |
14 | var x = 10;
15 | if (x === x) { /*error Comparing to itself is potentially pointless.*/
16 | x = 20;
17 | }
18 | ```
19 |
20 | ## Further Reading
21 |
22 | * [Weird Relation](http://jslinterrors.com/weird-relation/)
23 |
--------------------------------------------------------------------------------
/lib/rules/no-regex-spaces.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to count multiple spaces in regular expressions
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "Literal": function(node) {
17 | var token = context.getFirstToken(node),
18 | nodeType = token.type,
19 | nodeValue = token.value,
20 | multipleSpacesRegex = /( {2,})+?/,
21 | regexResults;
22 |
23 | if (nodeType === "RegularExpression") {
24 | regexResults = multipleSpacesRegex.exec(nodeValue);
25 |
26 | if (regexResults !== null) {
27 | context.report(node, "Spaces are hard to count. Use {" + regexResults[0].length + "}.");
28 | }
29 | }
30 | }
31 | };
32 |
33 | };
34 |
35 | module.exports.schema = [];
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | ESLint
2 | Copyright (c) 2013 Nicholas C. Zakas. All rights reserved.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/docs/rules/no-proto.md:
--------------------------------------------------------------------------------
1 | # Disallow Use of `__proto__` (no-proto)
2 |
3 | `__proto__` property has been deprecated as of ECMAScript 3.1 and shouldn't be used in the code. Use `getPrototypeOf` method instead.
4 |
5 | ## Rule Details
6 |
7 | When an object is created `__proto__` is set to the original prototype property of the object’s constructor function. `getPrototypeOf` is the preferred method of getting "the prototype".
8 |
9 | The following patterns are considered problems:
10 |
11 | ```js
12 | /*eslint no-proto: 2*/
13 |
14 | var a = obj.__proto__; /*error The '__proto__' property is deprecated.*/
15 |
16 | var a = obj["__proto__"]; /*error The '__proto__' property is deprecated.*/
17 | ```
18 |
19 | The following patterns are considered okay and could be used alternatively:
20 |
21 | ```js
22 | /*eslint no-proto: 2*/
23 |
24 | var a = Object.getPrototypeOf(obj);
25 | ```
26 |
27 | ## When not to use
28 |
29 | If you need to support legacy browsers, you might want to turn this rule off, since support for `getPrototypeOf` is not yet universal.
30 |
31 | ## Further Reading
32 |
33 | * [Object.getPrototypeOf](http://ejohn.org/blog/objectgetprototypeof/)
34 |
--------------------------------------------------------------------------------
/docs/rules/no-dupe-keys.md:
--------------------------------------------------------------------------------
1 | # Disallow Duplicate Keys (no-dupe-keys)
2 |
3 | Creating objects with duplicate keys in objects can cause unexpected behavior in your application. The `no-dupe-keys` rule flags the use of duplicate keys in object literals.
4 |
5 | ```js
6 | var foo = {
7 | bar: "baz",
8 | bar: "qux"
9 | };
10 | ```
11 |
12 | ## Rule Details
13 |
14 | This rule is aimed at preventing possible errors and unexpected behavior that might arise from using duplicate keys in object literals. As such, it warns whenever it finds a duplicate key.
15 |
16 | The following patterns are considered problems:
17 |
18 | ```js
19 | /*eslint no-dupe-keys: 2*/
20 |
21 | var foo = {
22 | bar: "baz",
23 | bar: "qux" /*error Duplicate key 'bar'.*/
24 | };
25 |
26 | var foo = {
27 | "bar": "baz",
28 | bar: "qux" /*error Duplicate key 'bar'.*/
29 | };
30 |
31 | var foo = {
32 | 0x1: "baz",
33 | 1: "qux" /*error Duplicate key '1'.*/
34 | };
35 | ```
36 |
37 | The following patterns are not considered problems:
38 |
39 | ```js
40 | /*eslint no-dupe-keys: 2*/
41 |
42 | var foo = {
43 | bar: "baz",
44 | quxx: "qux"
45 | };
46 | ```
47 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-undef-init.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for undefined rule.
3 | * @author Ilya Volodin
4 | * @copyright 2013 Ilya Volodin. All rights reserved.
5 | * See LICENSE in root directory for full license.
6 | */
7 |
8 | "use strict";
9 |
10 | //------------------------------------------------------------------------------
11 | // Requirements
12 | //------------------------------------------------------------------------------
13 |
14 | var rule = require("../../../lib/rules/no-undef-init"),
15 | RuleTester = require("../../../lib/testers/rule-tester");
16 |
17 | //------------------------------------------------------------------------------
18 | // Tests
19 | //------------------------------------------------------------------------------
20 |
21 | var ruleTester = new RuleTester();
22 | ruleTester.run("no-undef-init", rule, {
23 | valid: [
24 | "var a;",
25 | { code: "const foo = undefined", ecmaFeatures: { blockBindings: true } }
26 | ],
27 | invalid: [
28 | { code: "var a = undefined;", errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator"}] }
29 | ]
30 | });
31 |
--------------------------------------------------------------------------------
/lib/rules/no-new-func.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when using new Function
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | //--------------------------------------------------------------------------
15 | // Helpers
16 | //--------------------------------------------------------------------------
17 |
18 | /**
19 | * Checks if the callee if the Function constructor, and if so, reports an issue.
20 | * @param {ASTNode} node The node to check and report on
21 | * @returns {void}
22 | * @private
23 | */
24 | function validateCallee(node) {
25 | if (node.callee.name === "Function") {
26 | context.report(node, "The Function constructor is eval.");
27 | }
28 | }
29 |
30 | return {
31 | "NewExpression": validateCallee,
32 | "CallExpression": validateCallee
33 | };
34 |
35 | };
36 |
37 | module.exports.schema = [];
38 |
--------------------------------------------------------------------------------
/packages/eslint-config-eslint/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 Nicholas C. Zakas. All rights reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/docs/rules/no-debugger.md:
--------------------------------------------------------------------------------
1 | # Disallow debugger (no-debugger)
2 |
3 | The `debugger` statement is used to tell the executing JavaScript environment to stop execution and start up a debugger at the current point in the code. This has fallen out of favor as a good practice with the advent of modern debugging and development tools. Production code should definitely not contain `debugger`, as it will cause the browser to stop executing code and open an appropriate debugger.
4 |
5 | ```js
6 | debugger;
7 | ```
8 |
9 | ## Rule Details
10 |
11 | This rule is aimed at eliminating `debugger` references from your JavaScript. As such, it warns whenever it sees `debugger` used as an identifier in code.
12 |
13 | ## When Not To Use It
14 |
15 | If your code is still very much in development and don't want to worry about stripping about `debugger` statements, then turn this rule off. You'll generally want to turn it back on when testing code prior to deployment.
16 |
17 | ## Further Reading
18 |
19 | * [Debugger](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger)
20 |
21 | ## Related Rules
22 |
23 | * [no-alert](no-alert.md)
24 | * [no-console](no-console.md)
25 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-eval.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-eval rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-eval"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-eval", rule, {
21 | valid: [
22 | "Eval(foo)",
23 | "setTimeout('foo')",
24 | "setInterval('foo')",
25 | "window.setTimeout('foo')",
26 | "window.setInterval('foo')"
27 | ],
28 |
29 | invalid: [
30 | { code: "eval(foo)", errors: [{ message: "eval can be harmful.", type: "CallExpression"}] },
31 | { code: "eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression"}] }
32 | ]
33 | });
34 |
--------------------------------------------------------------------------------
/docs/rules/no-negated-in-lhs.md:
--------------------------------------------------------------------------------
1 | # Disallow negated left operand of `in` operator (no-negated-in-lhs)
2 |
3 | ## Rule Details
4 |
5 | This error is raised to highlight a potential error. Commonly, when a developer intends to write
6 |
7 | ```js
8 | if(!(a in b)) {
9 | // do something
10 | }
11 | ```
12 |
13 | they will instead write
14 |
15 | ```js
16 | if(!a in b) {
17 | // do something
18 | }
19 | ```
20 |
21 | If one intended the original behaviour, the left operand should be explicitly coerced to a string like below.
22 |
23 | ```js
24 | if(('' + !a) in b) {
25 | // do something
26 | }
27 | ```
28 |
29 | The following patterns are considered problems:
30 |
31 | ```js
32 | /*eslint no-negated-in-lhs: 2*/
33 |
34 | if(!a in b) { /*error The `in` expression's left operand is negated*/
35 | // do something
36 | }
37 | ```
38 |
39 | The following patterns are not considered problems:
40 |
41 | ```js
42 | /*eslint no-negated-in-lhs: 2*/
43 |
44 | if(!(a in b)) {
45 | // do something
46 | }
47 |
48 | if(('' + !a) in b) {
49 | // do something
50 | }
51 | ```
52 |
53 | ## When Not To Use It
54 |
55 | Never.
56 |
57 | ## Further Reading
58 |
59 | None.
60 |
--------------------------------------------------------------------------------
/lib/rules/no-ex-assign.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag assignment of the exception parameter
3 | * @author Stephen Murray
4 | */
5 |
6 | "use strict";
7 |
8 | var astUtils = require("../ast-utils");
9 |
10 | //------------------------------------------------------------------------------
11 | // Rule Definition
12 | //------------------------------------------------------------------------------
13 |
14 | module.exports = function(context) {
15 |
16 | /**
17 | * Finds and reports references that are non initializer and writable.
18 | * @param {Variable} variable - A variable to check.
19 | * @returns {void}
20 | */
21 | function checkVariable(variable) {
22 | astUtils.getModifyingReferences(variable.references).forEach(function(reference) {
23 | context.report(
24 | reference.identifier,
25 | "Do not assign to the exception parameter.");
26 | });
27 | }
28 |
29 | return {
30 | "CatchClause": function(node) {
31 | context.getDeclaredVariables(node).forEach(checkVariable);
32 | }
33 | };
34 |
35 | };
36 |
37 | module.exports.schema = [];
38 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/modify-ast-at-first.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule which modifies AST.
3 | * @author Toru Nagashima
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 | return {
14 | "Program": function(node) {
15 | node.body.push({
16 | "type": "Identifier",
17 | "name": "modified",
18 | "range": [0, 8],
19 | "loc": {
20 | "start": {
21 | "line": 1,
22 | "column": 0
23 | },
24 | "end": {
25 | "line": 1,
26 | "column": 8
27 | }
28 | }
29 | });
30 | },
31 |
32 | "Identifier": function(node) {
33 | if (node.name === "bar") {
34 | context.report({message: "error", node: node});
35 | }
36 | }
37 | };
38 | };
39 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-caller.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-caller rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-caller"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-caller", rule, {
21 | valid: [
22 | "var x = arguments.length",
23 | "var x = arguments",
24 | "var x = arguments[0]",
25 | "var x = arguments[caller]"
26 | ],
27 | invalid: [
28 | { code: "var x = arguments.callee", errors: [{ message: "Avoid arguments.callee.", type: "MemberExpression"}] },
29 | { code: "var x = arguments.caller", errors: [{ message: "Avoid arguments.caller.", type: "MemberExpression"}] }
30 | ]
31 | });
32 |
--------------------------------------------------------------------------------
/docs/rules/no-nested-ternary.md:
--------------------------------------------------------------------------------
1 | # Disallow Nested Ternaries (no-nested-ternary)
2 |
3 | Nesting ternary expressions makes code unclear. The `no-nested-ternary` rule disallows the use of nested ternary expressions.
4 |
5 | ```js
6 | var foo = bar ? baz : qux === quxx ? bing : bam;
7 | ```
8 |
9 | ## Rule Details
10 |
11 | The `no-nested-ternary` rule aims to increase the clarity and readability of code by disallowing the use of nested ternary expressions.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-nested-ternary: 2*/
17 |
18 | var thing = foo ? bar : baz === qux ? quxx : foobar; /*error Do not nest ternary expressions*/
19 |
20 | foo ? baz === qux ? quxx() : foobar() : bar(); /*error Do not nest ternary expressions*/
21 | ```
22 |
23 | The following patterns are considered okay and could be used alternatively:
24 |
25 | ```js
26 | /*eslint no-nested-ternary: 2*/
27 |
28 | var thing;
29 |
30 | if (foo) {
31 | thing = bar;
32 | } else if (baz === qux) {
33 | thing = quxx;
34 | } else {
35 | thing = foobar;
36 | }
37 | ```
38 |
39 | ## Related Rules
40 |
41 | * [no-ternary](no-ternary.md)
42 | * [no-unneeded-ternary](no-unneeded-ternary.md)
43 |
--------------------------------------------------------------------------------
/tests/fixtures/testers/rule-tester/modify-ast-at-last.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule which modifies AST.
3 | * @author Toru Nagashima
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 | return {
14 | "Program:exit": function(node) {
15 | node.body.push({
16 | "type": "Identifier",
17 | "name": "modified",
18 | "range": [0, 8],
19 | "loc": {
20 | "start": {
21 | "line": 1,
22 | "column": 0
23 | },
24 | "end": {
25 | "line": 1,
26 | "column": 8
27 | }
28 | }
29 | });
30 | },
31 |
32 | "Identifier": function(node) {
33 | if (node.name === "bar") {
34 | context.report({message: "error", node: node});
35 | }
36 | }
37 | };
38 | };
39 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-console.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-console rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-console"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-console", rule, {
21 | valid: [
22 | "Console.info(foo)"
23 | ],
24 | invalid: [
25 | { code: "console.log(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression"}] },
26 | { code: "console.error(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression"}] },
27 | { code: "console.info(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-lonely-if.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-lonely-if rule.
3 | * @author Brandon Mills
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Requirements
9 | //------------------------------------------------------------------------------
10 |
11 | var rule = require("../../../lib/rules/no-lonely-if"),
12 | RuleTester = require("../../../lib/testers/rule-tester");
13 |
14 | //------------------------------------------------------------------------------
15 | // Tests
16 | //------------------------------------------------------------------------------
17 |
18 | var ruleTester = new RuleTester();
19 | ruleTester.run("no-lonely-if", rule, {
20 |
21 | // Examples of code that should not trigger the rule
22 | valid: [
23 | "if (a) {;} else if (b) {;}",
24 | "if (a) {;} else { if (b) {;} ; }"
25 | ],
26 |
27 | // Examples of code that should trigger the rule
28 | invalid: [{
29 | code: "if (a) {;} else { if (b) {;} }",
30 | errors: [{
31 | message: "Unexpected if as the only statement in an else block.",
32 | type: "IfStatement"
33 | }]
34 | }]
35 | });
36 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-nested-ternary.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for the no-nested-ternary rule
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-nested-ternary"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-nested-ternary", rule, {
21 | valid: [
22 | "foo ? doBar() : doBaz();",
23 | "var foo = bar === baz ? qux : quxx;"
24 | ],
25 | invalid: [
26 | { code: "foo ? bar : baz === qux ? quxx : foobar;", errors: [{ message: "Do not nest ternary expressions", type: "ConditionalExpression"}] },
27 | { code: "foo ? baz === qux ? quxx : foobar : bar;", errors: [{ message: "Do not nest ternary expressions", type: "ConditionalExpression"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-ternary.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-ternary.
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-ternary"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-ternary", rule, {
21 | valid: [
22 | "\"x ? y\";"
23 | ],
24 | invalid: [
25 | { code: "var foo = true ? thing : stuff;", errors: [{ message: "Ternary operator used.", type: "ConditionalExpression"}] },
26 | { code: "true ? thing() : stuff();", errors: [{ message: "Ternary operator used.", type: "ConditionalExpression"}] },
27 | { code: "function foo(bar) { return bar ? baz : qux; }", errors: [{ message: "Ternary operator used.", type: "ConditionalExpression"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/lib/rules/no-labels.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow Labeled Statements
3 | * @author Nicholas C. Zakas
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Rule Definition
9 | //------------------------------------------------------------------------------
10 |
11 | module.exports = function(context) {
12 |
13 | //--------------------------------------------------------------------------
14 | // Public
15 | //--------------------------------------------------------------------------
16 |
17 | return {
18 |
19 | "LabeledStatement": function(node) {
20 | context.report(node, "Unexpected labeled statement.");
21 | },
22 |
23 | "BreakStatement": function(node) {
24 |
25 | if (node.label) {
26 | context.report(node, "Unexpected label in break statement.");
27 | }
28 |
29 | },
30 |
31 | "ContinueStatement": function(node) {
32 |
33 | if (node.label) {
34 | context.report(node, "Unexpected label in continue statement.");
35 | }
36 |
37 | }
38 |
39 |
40 | };
41 |
42 | };
43 |
44 | module.exports.schema = [];
45 |
--------------------------------------------------------------------------------
/lib/rules/no-octal-escape.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag octal escape sequences in string literals.
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "Literal": function(node) {
17 | if (typeof node.value !== "string") {
18 | return;
19 | }
20 |
21 | var match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-3][0-7]{1,2}|[4-7][0-7]|[0-7])/),
22 | octalDigit;
23 |
24 | if (match) {
25 | octalDigit = match[2];
26 |
27 | // \0 is actually not considered an octal
28 | if (match[2] !== "0" || typeof match[3] !== "undefined") {
29 | context.report(node, "Don't use octal: '\\{{octalDigit}}'. Use '\\u....' instead.",
30 | { octalDigit: octalDigit });
31 | }
32 | }
33 | }
34 |
35 | };
36 |
37 | };
38 |
39 | module.exports.schema = [];
40 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-multi-str.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-multi-str rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-multi-str"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-multi-str", rule, {
21 | valid: [
22 | "var a = 'Line 1 Line 2';",
23 | { code: "var a = \n
Wat
\n;", ecmaFeatures: { jsx: true }}
24 | ],
25 | invalid: [
26 | { code: "var x = 'Line 1 \\\n Line 2'", errors: [{ message: "Multiline support is limited to browsers supporting ES5 only.", type: "Literal"}] },
27 | { code: "test('Line 1 \\\n Line 2');", errors: [{ message: "Multiline support is limited to browsers supporting ES5 only.", type: "Literal"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-new-func.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-new-func rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-new-func"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-new-func", rule, {
21 | valid: [
22 | "var a = new _function(\"b\", \"c\", \"return b+c\");",
23 | "var a = _function(\"b\", \"c\", \"return b+c\");"
24 | ],
25 | invalid: [
26 | { code: "var a = new Function(\"b\", \"c\", \"return b+c\");", errors: [{ message: "The Function constructor is eval.", type: "NewExpression"}] },
27 | { code: "var a = Function(\"b\", \"c\", \"return b+c\");", errors: [{ message: "The Function constructor is eval.", type: "CallExpression"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/docs/rules/no-wrap-func.md:
--------------------------------------------------------------------------------
1 | # Disallow Parens Around Functions (no-wrap-func)
2 |
3 | **Replacement notice**: This rule was removed in ESLint v1.0 and replaced by the [no-extra-parens](no-extra-parens.md) rule, when configured in the `"functions"` mode.
4 |
5 |
6 | Although it's possible to wrap functions in parentheses, this can be confusing when the code also contains immediately-invoked function expressions (IIFEs) since parentheses are often used to make this distinction. For example:
7 |
8 | ```js
9 | var foo = (function() {
10 | // IIFE
11 | }());
12 |
13 | var bar = (function() {
14 | // not an IIFE
15 | });
16 | ```
17 |
18 | ## Rule Details
19 |
20 | This rule will raise a warning when it encounters a function expression wrapped in parentheses with no following invoking parentheses.
21 |
22 | The following patterns are considered problems:
23 |
24 | ```js
25 | var a = (function() {/*...*/});
26 | ```
27 |
28 | The following patterns are not considered problems:
29 |
30 | ```js
31 | var a = function() {/*...*/};
32 |
33 | (function() {/*...*/})();
34 | ```
35 |
36 | ## Further Reading
37 |
38 | * [Do not wrap function literals in parens unless they are to be immediately invoked](http://jslinterrors.com/do-not-wrap-function-literals-in-parens)
39 |
--------------------------------------------------------------------------------
/packages/eslint-config-eslint/README.md:
--------------------------------------------------------------------------------
1 | [![NPM version][npm-image]][npm-url]
2 | [](https://gitter.im/eslint/eslint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3 |
4 | # ESLint Configuration
5 |
6 | [Website](http://eslint.org) | [Configuring](http://eslint.org/docs/user-guide/configuring) | [Rules](http://eslint.org/docs/rules/) | [Contributing](http://eslint.org/docs/developer-guide/contributing) | [Twitter](https://twitter.com/geteslint) | [Mailing List](https://groups.google.com/group/eslint)
7 |
8 | Contains the default ESLint configuration for ESLint projects.
9 |
10 | ## Installation
11 |
12 | You can install ESLint using npm:
13 |
14 | npm install eslint --save-dev
15 |
16 | Then install this configuration:
17 |
18 | npm install eslint-config-eslint --save-dev
19 |
20 | ## Usage
21 |
22 | In your `.eslintrc` file, add:
23 |
24 | ```json
25 | {
26 | "extends": "eslint"
27 | }
28 | ```
29 |
30 | ### Where to ask for help?
31 |
32 | Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://gitter.im/eslint/eslint)
33 |
34 | [npm-image]: https://img.shields.io/npm/v/eslint.svg?style=flat-square
35 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-empty-label.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-empty-label rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-empty-label"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-empty-label", rule, {
21 | valid: [
22 | "labeled: for (var i in {}) { }",
23 | { code: "labeled: for (var i of {}) { }", ecmaFeatures: { forOf: true } },
24 | "labeled: for (var i=10; i; i--) { }",
25 | "labeled: while(i) {}",
26 | "labeled: do {} while (i)",
27 | "labeled: switch(i) { case 1: break; default: break; }"
28 | ],
29 | invalid: [
30 | { code: "labeled: var a = 10;", errors: [{ message: "Unexpected label \"labeled\"", type: "LabeledStatement"}] }
31 | ]
32 | });
33 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-eq-null.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-eq-null rule.
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-eq-null"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-eq-null", rule, {
21 | valid: [
22 | "if (x === null) { }",
23 | "if (null === f()) { }"
24 | ],
25 | invalid: [
26 | { code: "if (x == null) { }", errors: [{ message: "Use ‘===’ to compare with ‘null’.", type: "BinaryExpression"}] },
27 | { code: "if (x != null) { }", errors: [{ message: "Use ‘===’ to compare with ‘null’.", type: "BinaryExpression"}] },
28 | { code: "do {} while (null == x)", errors: [{ message: "Use ‘===’ to compare with ‘null’.", type: "BinaryExpression"}] }
29 | ]
30 | });
31 |
--------------------------------------------------------------------------------
/docs/rules/use-isnan.md:
--------------------------------------------------------------------------------
1 | # Require isNaN() (use-isnan)
2 |
3 | In JavaScript, `NaN` is a special value of the `Number` type. It's used to represent any of the "not-a-number" values represented by the double-precision 64-bit format as specified by the IEEE Standard for Binary Floating-Point Arithmetic. `NaN` has the unique property of not being equal to anything, including itself. That is to say, that the condition `NaN !== NaN` evaluates to true.
4 |
5 | ## Rule Details
6 |
7 | This rule is aimed at eliminating potential errors as the result of comparing against the special value `NaN`.
8 |
9 | The following patterns are considered problems:
10 |
11 | ```js
12 | /*eslint use-isnan: 2*/
13 |
14 | if (foo == NaN) { /*error Use the isNaN function to compare with NaN.*/
15 | // ...
16 | }
17 |
18 | if (foo != NaN) { /*error Use the isNaN function to compare with NaN.*/
19 | // ...
20 | }
21 | ```
22 |
23 | The following patterns are not considered problems:
24 |
25 | ```js
26 | /*eslint use-isnan: 2*/
27 |
28 | if (isNaN(foo)) {
29 | // ...
30 | }
31 |
32 | if (isNaN(NaN)) {
33 | // ...
34 | }
35 | ```
36 |
37 | ## Further reading
38 |
39 | * [Use the isNaN function to compare with NaN](http://jslinterrors.com/use-the-isnan-function-to-compare-with-nan/)
40 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-octal.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-octal rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-octal"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-octal", rule, {
21 | valid: [
22 | "var a = 'hello world';",
23 | "0x1234",
24 | "0X5;",
25 | "a = 0;",
26 | "0.1",
27 | "0.5e1"
28 | ],
29 | invalid: [
30 | { code: "var a = 01234;", errors: [{ message: "Octal literals should not be used.", type: "Literal"}] },
31 | { code: "a = 1 + 01234;", errors: [{ message: "Octal literals should not be used.", type: "Literal"}] },
32 | { code: "00", errors: [{ message: "Octal literals should not be used.", type: "Literal"}] }
33 | ]
34 | });
35 |
--------------------------------------------------------------------------------
/lib/formatters/jslint-xml.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview JSLint XML reporter
3 | * @author Ian Christian Myers
4 | */
5 | "use strict";
6 |
7 | var xmlescape = require("xml-escape");
8 |
9 | //------------------------------------------------------------------------------
10 | // Public Interface
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(results) {
14 |
15 | var output = "";
16 |
17 | output += "";
18 | output += "";
19 |
20 | results.forEach(function(result) {
21 | var messages = result.messages;
22 |
23 | output += "";
24 |
25 | messages.forEach(function(message) {
26 | output += "";
31 | });
32 |
33 | output += "";
34 |
35 | });
36 |
37 | output += "";
38 |
39 | return output;
40 | };
41 |
--------------------------------------------------------------------------------
/lib/rules/no-path-concat.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow string concatenation when using __dirname and __filename
3 | * @author Nicholas C. Zakas
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Rule Definition
9 | //------------------------------------------------------------------------------
10 |
11 | module.exports = function(context) {
12 |
13 | var MATCHER = /^__(?:dir|file)name$/;
14 |
15 | //--------------------------------------------------------------------------
16 | // Public
17 | //--------------------------------------------------------------------------
18 |
19 | return {
20 |
21 | "BinaryExpression": function(node) {
22 |
23 | var left = node.left,
24 | right = node.right;
25 |
26 | if (node.operator === "+" &&
27 | ((left.type === "Identifier" && MATCHER.test(left.name)) ||
28 | (right.type === "Identifier" && MATCHER.test(right.name)))
29 | ) {
30 |
31 | context.report(node, "Use path.join() or path.resolve() instead of + to create paths.");
32 | }
33 | }
34 |
35 | };
36 |
37 | };
38 |
39 | module.exports.schema = [];
40 |
--------------------------------------------------------------------------------
/tests/lib/rules/wrap-regex.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for wrap-regex rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/wrap-regex"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 |
20 | var ruleTester = new RuleTester();
21 | ruleTester.run("wrap-regex", rule, {
22 | valid: [
23 | "(/foo/).test(bar);",
24 | "(/foo/ig).test(bar);",
25 | "/foo/;",
26 | "var f = 0;",
27 | "a[/b/];"
28 | ],
29 | invalid: [
30 | { code: "/foo/.test(bar);",
31 | errors: [{ message: "Wrap the regexp literal in parens to disambiguate the slash.", type: "Literal"}] },
32 | { code: "/foo/ig.test(bar);",
33 | errors: [{ message: "Wrap the regexp literal in parens to disambiguate the slash.", type: "Literal"}] }
34 |
35 | ]
36 | });
37 |
--------------------------------------------------------------------------------
/docs/rules/no-extra-semi.md:
--------------------------------------------------------------------------------
1 | # Disallow Extra Semicolons (no-extra-semi)
2 |
3 | JavaScript will more or less let you put semicolons after any statement without complaining. Typos and misunderstandings about where semicolons are required can lead to extra semicolons that are unnecessary.
4 |
5 | **Fixable:** This rule is automatically fixable using the `--fix` flag on the command line.
6 |
7 | ## Rule Details
8 |
9 | This rule is aimed at eliminating extra unnecessary semicolons. While not technically an error, extra semicolons can be a source of confusion when reading code.
10 |
11 | The following patterns are considered problems:
12 |
13 | ```js
14 | /*eslint no-extra-semi: 2*/
15 |
16 | var x = 5;; /*error Unnecessary semicolon.*/
17 |
18 | function foo() {
19 | // code
20 | }; /*error Unnecessary semicolon.*/
21 |
22 | ```
23 |
24 | The following patterns are not considered problems:
25 |
26 | ```js
27 | /*eslint no-extra-semi: 2*/
28 |
29 | var x = 5;
30 |
31 | var foo = function() {
32 | // code
33 | };
34 |
35 | ```
36 |
37 | ## When Not To Use It
38 |
39 | If you intentionally use extra semicolons then you can disable this rule.
40 |
41 | ## Related Rules
42 |
43 | * [semi](semi.md)
44 | * [no-space-before-semi](no-space-before-semi.md)
45 |
--------------------------------------------------------------------------------
/docs/rules/eol-last.md:
--------------------------------------------------------------------------------
1 | # Require file to end with single newline (eol-last)
2 |
3 | Trailing newlines in non-empty files are a common UNIX idiom. Benefits of
4 | trailing newlines include the ability to concatenate or append to files as well
5 | as output files to the terminal without interfering with shell prompts. This
6 | rule enforces newlines for all non-empty programs.
7 |
8 | Prior to v0.16.0 this rule also enforced that there was only a single line at
9 | the end of the file. If you still want this behaviour, consider enabling
10 | [no-multiple-empty-lines](no-multiple-empty-lines.md) with `maxEOF` and/or
11 | [no-trailing-spaces](no-trailing-spaces.md).
12 |
13 | **Fixable:** This rule is automatically fixable using the `--fix` flag on the command line.
14 |
15 | ## Rule Details
16 |
17 | The following patterns are considered problems:
18 |
19 | ```js
20 | /*eslint eol-last: 2*/
21 |
22 | function doSmth() {
23 | var foo = 2;
24 | }
25 | ```
26 |
27 | The following patterns are not considered problems:
28 |
29 | ```js
30 | /*eslint eol-last: 2*/
31 |
32 | function doSmth() {
33 | var foo = 2;
34 | }
35 | // spaces here
36 | ```
37 |
38 | ### Options
39 |
40 | This rule may take one option which is either `unix` (LF) or `windows` (CRLF). When omitted `unix` is assumed.
41 |
--------------------------------------------------------------------------------
/docs/rules/no-obj-calls.md:
--------------------------------------------------------------------------------
1 | # Disallow Global Object Function Calls (no-obj-calls)
2 |
3 | ECMAScript provides several global objects that are intended to be used as-is. Some of these objects look as if they could be constructors due their capitalization (such as `Math` and `JSON`) but will throw an error if you try to execute them as functions.
4 |
5 | The [ECMAScript 5 specification](http://es5.github.io/#x15.8) makes it clear that both `Math` and `JSON` cannot be invoked:
6 |
7 | > The Math object does not have a `[[Call]]` internal property; it is not possible to invoke the Math object as a function.
8 |
9 | ## Rule Details
10 |
11 | This rule is aimed at preventing the accidental calling of global objects as functions.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-obj-calls: 2*/
17 |
18 | var x = Math(); /*error 'Math' is not a function.*/
19 | var y = JSON(); /*error 'JSON' is not a function.*/
20 | ```
21 |
22 | The following patterns are not considered problems:
23 |
24 | ```js
25 | /*eslint no-obj-calls: 2*/
26 |
27 | var x = math();
28 | var y = json();
29 | ```
30 |
31 | ## Further Reading
32 |
33 | * [The Math Object](http://es5.github.io/#x15.8)
34 | * ['{a}' is not a function](http://jslinterrors.com/a-is-not-a-function/)
35 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-floating-decimal.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-floating-decimal rule.
3 | * @author James Allardice
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-floating-decimal"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-floating-decimal", rule, {
21 | valid: [
22 | "var x = 2.5;",
23 | "var x = \"2.5\";"
24 | ],
25 | invalid: [
26 | { code: "var x = .5;", errors: [{ message: "A leading decimal point can be confused with a dot.", type: "Literal"}] },
27 | { code: "var x = -.5;", errors: [{ message: "A leading decimal point can be confused with a dot.", type: "Literal"}] },
28 | { code: "var x = 2.;", errors: [{ message: "A trailing decimal point can be confused with a dot.", type: "Literal"}] }
29 | ]
30 | });
31 |
--------------------------------------------------------------------------------
/lib/util/keywords.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview A shared list of ES3 keywords.
3 | * @author Josh Perez
4 | * @copyright 2015 Jose Roberto Vidal. All rights reserved.
5 | */
6 | "use strict";
7 |
8 | module.exports = [
9 | "abstract",
10 | "boolean",
11 | "break",
12 | "byte",
13 | "case",
14 | "catch",
15 | "char",
16 | "class",
17 | "const",
18 | "continue",
19 | "debugger",
20 | "default",
21 | "delete",
22 | "do",
23 | "double",
24 | "else",
25 | "enum",
26 | "export",
27 | "extends",
28 | "false",
29 | "final",
30 | "finally",
31 | "float",
32 | "for",
33 | "function",
34 | "goto",
35 | "if",
36 | "implements",
37 | "import",
38 | "in",
39 | "instanceof",
40 | "int",
41 | "interface",
42 | "long",
43 | "native",
44 | "new",
45 | "null",
46 | "package",
47 | "private",
48 | "protected",
49 | "public",
50 | "return",
51 | "short",
52 | "static",
53 | "super",
54 | "switch",
55 | "synchronized",
56 | "this",
57 | "throw",
58 | "throws",
59 | "transient",
60 | "true",
61 | "try",
62 | "typeof",
63 | "var",
64 | "void",
65 | "volatile",
66 | "while",
67 | "with"
68 | ];
69 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-new-require.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-new-require rule.
3 | * @author Wil Moore III
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-new-require"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-new-require", rule, {
21 | valid: [
22 | "var appHeader = require('app-header')",
23 | "var AppHeader = new (require('app-header'))",
24 | "var AppHeader = new (require('headers').appHeader)"
25 | ],
26 | invalid: [
27 | { code: "var appHeader = new require('app-header')", errors: [{ message: "Unexpected use of new with require.", type: "NewExpression"}] },
28 | { code: "var appHeader = new require('headers').appHeader", errors: [{ message: "Unexpected use of new with require.", type: "NewExpression"}] }
29 | ]
30 | });
31 |
--------------------------------------------------------------------------------
/docs/rules/func-names.md:
--------------------------------------------------------------------------------
1 | # Require Function Expressions to have a Name (func-names)
2 |
3 | A pattern that's becoming more common is to give function expressions names to aid in debugging, such as:
4 |
5 | ```js
6 | Foo.prototype.bar = function bar() {};
7 | ```
8 |
9 | Adding the second `bar` in the above example is optional. If you leave off the function name then when the function throws an exception you are likely to get something similar to `anonymous function` in the stack trace. If you provide the optional name for a function expression then you will get the name of the function expression in the stack trace.
10 |
11 | ## Rule Details
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /* eslint func-names: 2*/
17 |
18 | Foo.prototype.bar = function() {}; /*error Missing function expression name.*/
19 |
20 | (function() { /*error Missing function expression name.*/
21 | // ...
22 | }())
23 | ```
24 |
25 | The following patterns are not considered problems:
26 |
27 | ```js
28 | /* eslint func-names: 2*/
29 |
30 | Foo.prototype.bar = function bar() {};
31 |
32 | (function bar() {
33 | // ...
34 | }())
35 | ```
36 |
37 | ## Further Reading
38 |
39 | * [Functions Explained](http://markdaggett.com/blog/2013/02/15/functions-explained/)
40 |
--------------------------------------------------------------------------------
/tests/lib/rules/guard-for-in.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for guard-for-in rule.
3 | * @author Nicholas C. Zakas
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/guard-for-in"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("guard-for-in", rule, {
21 | valid: [
22 | "for (var x in o) {}",
23 | "for (var x in o) { if (x) {}}"
24 | ],
25 | invalid: [
26 | { code: "for (var x in o) { foo() }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement"}] },
27 | { code: "for (var x in o) foo();", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement"}] }
28 | ]
29 | });
30 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-iterator.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-iterator rule.
3 | * @author Ian Christian Myers
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-iterator"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-iterator", rule, {
21 | valid: [
22 | "var a = test[__iterator__];",
23 | "var __iterator__ = null;"
24 | ],
25 | invalid: [
26 | { code: "var a = test.__iterator__;", errors: [{ message: "Reserved name '__iterator__'.", type: "MemberExpression"}] },
27 | { code: "Foo.prototype.__iterator__ = function() {};", errors: [{ message: "Reserved name '__iterator__'.", type: "MemberExpression"}] },
28 | { code: "var a = test['__iterator__'];", errors: [{ message: "Reserved name '__iterator__'.", type: "MemberExpression"}] }
29 | ]
30 | });
31 |
--------------------------------------------------------------------------------
/docs/rules/no-new-func.md:
--------------------------------------------------------------------------------
1 | # Disallow Function Constructor (no-new-func)
2 |
3 | It's possible to create functions in JavaScript using the `Function` constructor, such as:
4 |
5 | ```js
6 | var x = new Function("a", "b", "return a + b");
7 | ```
8 |
9 | This is considered by many to be a bad practice due to the difficult in debugging and reading these types of functions.
10 |
11 | ## Rule Details
12 |
13 | This error is raised to highlight the use of a bad practice. By passing a string to the Function constructor, you are requiring the engine to parse that string much in the way it has to when you call the eval function.
14 |
15 | ```js
16 | /*eslint no-new-func: 2*/
17 |
18 | var x = new Function("a", "b", "return a + b"); /*error The Function constructor is eval.*/
19 | var x = Function("a", "b", "return a + b"); /*error The Function constructor is eval.*/
20 | ```
21 |
22 | The following patterns are not considered problems:
23 |
24 | ```js
25 | /*eslint no-new-func: 2*/
26 |
27 | var x = function (a, b) {
28 | return a + b;
29 | };
30 | ```
31 |
32 | ## When Not To Use It
33 |
34 | In more advanced cases where you really need to use the `Function` constructor.
35 |
36 | ## Further Reading
37 |
38 | * [The Function constructor is eval](http://jslinterrors.com/the-function-constructor-is-eval/)
39 |
--------------------------------------------------------------------------------
/docs/rules/no-octal.md:
--------------------------------------------------------------------------------
1 | # Disallow Octal Literals (no-octal)
2 |
3 | Octal literals are numerals that begin with a leading zero, such as:
4 |
5 | ```js
6 | var num = 071; // 57
7 | ```
8 |
9 | The leading zero to identify an octal literal has been a source of confusion and error in JavaScript. ECMAScript 5 deprecates the use of octal numeric literals in JavaScript and octal literals cause syntax errors in strict mode.
10 |
11 | It's therefore recommended to avoid using octal literals in JavaScript code.
12 |
13 | ## Rule Details
14 |
15 | The rule is aimed at preventing the use of a deprecated JavaScript feature, the use of octal literals. As such it will warn whenever an octal literal is found.
16 |
17 | The following patterns are considered problems:
18 |
19 | ```js
20 | /*eslint no-octal: 2*/
21 |
22 | var num = 071; /*error Octal literals should not be used.*/
23 | var result = 5 + 07; /*error Octal literals should not be used.*/
24 | ```
25 |
26 | The following patterns are not considered problems:
27 |
28 | ```js
29 | /*eslint no-octal: 2*/
30 |
31 | var num = "071";
32 | ```
33 |
34 | ## Compatibility
35 |
36 | * **JSHint**: W115
37 |
38 | ## Further Reading
39 |
40 | * [Octal literals not allowed in strict mode](http://jslinterrors.com/octal-literals-are-not-allowed-in-strict-mode)
41 |
--------------------------------------------------------------------------------
/docs/rules/no-ternary.md:
--------------------------------------------------------------------------------
1 | # Disallow Ternary Operators (no-ternary)
2 |
3 | The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to unclear code.
4 |
5 | ```js
6 | var foo = isBar ? baz : qux;
7 | ```
8 |
9 | ## Rule Details
10 |
11 | The `no-ternary` rule aims to disallow the use of ternary operators.
12 |
13 | The following patterns are considered problems:
14 |
15 | ```js
16 | /*eslint no-ternary: 2*/
17 |
18 | var foo = isBar ? baz : qux; /*error Ternary operator used.*/
19 |
20 | foo ? bar() : baz(); /*error Ternary operator used.*/
21 |
22 | function quux() {
23 | return foo ? bar : baz; /*error Ternary operator used.*/
24 | }
25 | ```
26 |
27 | The following patterns are considered okay and could be used alternatively:
28 |
29 | ```js
30 | /*eslint no-ternary: 2*/
31 |
32 | var foo;
33 |
34 | if (isBar) {
35 | foo = baz;
36 | } else {
37 | foo = qux;
38 | }
39 |
40 | if (foo) {
41 | bar();
42 | } else {
43 | baz();
44 | }
45 |
46 | function quux() {
47 | if (foo) {
48 | return bar;
49 | } else {
50 | return baz;
51 | }
52 | }
53 | ```
54 |
55 | ## Related Rules
56 |
57 | * [no-nested-ternary](no-nested-ternary.md)
58 | * [no-unneeded-ternary](no-unneeded-ternary.md)
59 |
--------------------------------------------------------------------------------
/docs/rules/prefer-template.md:
--------------------------------------------------------------------------------
1 | # Suggest using template literals instead of string concatenation. (prefer-template)
2 |
3 | In ES2015 (ES6), we can use template literals instead of string concatenation.
4 |
5 | ```js
6 | var str = "Hello, " + name + "!";
7 | ```
8 |
9 | ```js
10 | /*eslint-env es6*/
11 |
12 | var str = `Hello, ${name}!`;
13 | ```
14 |
15 | ## Rule Details
16 |
17 | This rule is aimed to flag usage of `+` operators with strings.
18 |
19 | The following patterns are considered problems:
20 |
21 | ```js
22 | /*eslint prefer-template: 2*/
23 |
24 | var str = "Hello, " + name + "!"; /*error Unexpected string concatenation.*/
25 | var str = "Time: " + (12 * 60 * 60 * 1000); /*error Unexpected string concatenation.*/
26 | ```
27 |
28 | The following patterns are not considered problems:
29 |
30 | ```js
31 | /*eslint prefer-template: 2*/
32 | /*eslint-env es6*/
33 |
34 | var str = "Hello World!";
35 | var str = `Hello, ${name}!`;
36 | var str = `Time: ${12 * 60 * 60}`;
37 |
38 | // This is reported by `no-useless-concat`.
39 | var str = "Hello, " + "World!";
40 | ```
41 |
42 | ## When Not to Use It
43 |
44 | This rule should not be used in ES3/5 environments.
45 |
46 | In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.
47 |
--------------------------------------------------------------------------------
/lib/rules/no-plusplus.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of unary increment and decrement operators.
3 | * @author Ian Christian Myers
4 | * @author Brody McKee (github.com/mrmckeb)
5 | */
6 |
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Rule Definition
11 | //------------------------------------------------------------------------------
12 |
13 | module.exports = function(context) {
14 |
15 | var config = context.options[0],
16 | allowInForAfterthought = false;
17 |
18 | if (typeof config === "object") {
19 | allowInForAfterthought = config.allowForLoopAfterthoughts === true;
20 | }
21 |
22 | return {
23 |
24 | "UpdateExpression": function(node) {
25 | if (allowInForAfterthought && node.parent.type === "ForStatement") {
26 | return;
27 | }
28 | context.report(node, "Unary operator '" + node.operator + "' used.");
29 | }
30 |
31 | };
32 |
33 | };
34 |
35 | module.exports.schema = [
36 | {
37 | "type": "object",
38 | "properties": {
39 | "allowForLoopAfterthoughts": {
40 | "type": "boolean"
41 | }
42 | },
43 | "additionalProperties": false
44 | }
45 | ];
46 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-sparse-arrays.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Disallow sparse arrays
3 | * @author Nicholas C. Zakas
4 | */
5 | "use strict";
6 |
7 | //------------------------------------------------------------------------------
8 | // Requirements
9 | //------------------------------------------------------------------------------
10 |
11 | var rule = require("../../../lib/rules/no-sparse-arrays"),
12 | RuleTester = require("../../../lib/testers/rule-tester");
13 |
14 | //------------------------------------------------------------------------------
15 | // Tests
16 | //------------------------------------------------------------------------------
17 |
18 | var ruleTester = new RuleTester();
19 | ruleTester.run("no-sparse-arrays", rule, {
20 |
21 | valid: [
22 | "var a = [ 1, 2, ]"
23 | ],
24 |
25 | invalid: [
26 | {
27 | code: "var a = [,];",
28 | errors: [{
29 | message: "Unexpected comma in middle of array.",
30 | type: "ArrayExpression"
31 | }]
32 | },
33 | {
34 | code: "var a = [ 1,, 2];",
35 | errors: [{
36 | message: "Unexpected comma in middle of array.",
37 | type: "ArrayExpression"
38 | }]
39 | }
40 | ]
41 | });
42 |
--------------------------------------------------------------------------------
/lib/rules/wrap-regex.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag when regex literals are not wrapped in parens
3 | * @author Matt DuVall
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | module.exports = function(context) {
13 |
14 | return {
15 |
16 | "Literal": function(node) {
17 | var token = context.getFirstToken(node),
18 | nodeType = token.type,
19 | source,
20 | grandparent,
21 | ancestors;
22 |
23 | if (nodeType === "RegularExpression") {
24 | source = context.getTokenBefore(node);
25 | ancestors = context.getAncestors();
26 | grandparent = ancestors[ancestors.length - 1];
27 |
28 | if (grandparent.type === "MemberExpression" && grandparent.object === node &&
29 | (!source || source.value !== "(")) {
30 | context.report(node, "Wrap the regexp literal in parens to disambiguate the slash.");
31 | }
32 | }
33 | }
34 | };
35 |
36 | };
37 |
38 | module.exports.schema = [];
39 |
--------------------------------------------------------------------------------
/tests/lib/rules/no-script-url.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Tests for no-script-url rule.
3 | * @author Ilya Volodin
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var rule = require("../../../lib/rules/no-script-url"),
13 | RuleTester = require("../../../lib/testers/rule-tester");
14 |
15 | //------------------------------------------------------------------------------
16 | // Tests
17 | //------------------------------------------------------------------------------
18 |
19 | var ruleTester = new RuleTester();
20 | ruleTester.run("no-script-url", rule, {
21 | valid: [
22 | "var a = 'Hello World!';",
23 | "var a = 10;",
24 | "var url = 'xjavascript:'"
25 | ],
26 | invalid: [
27 | {
28 | code: "var a = 'javascript:void(0);';",
29 | errors: [
30 | { message: "Script URL is a form of eval.", type: "Literal"}
31 | ]
32 | },
33 | {
34 | code: "var a = 'javascript:';",
35 | errors: [
36 | { message: "Script URL is a form of eval.", type: "Literal"}
37 | ]
38 | }
39 | ]
40 | });
41 |
--------------------------------------------------------------------------------
/docs/rules/no-comma-dangle.md:
--------------------------------------------------------------------------------
1 | # Disallow Dangling Commas (no-comma-dangle)
2 |
3 | **Replacement notice**: This rule was removed in ESLint v1.0 and replaced by the [comma-dangle](comma-dangle.md) rule.
4 |
5 | Trailing commas in object literals are valid according to the ECMAScript 5 (and ECMAScript 3!) spec, however IE8 (when not in IE8 document mode) and below will throw an error when it encounters trailing commas in JavaScript.
6 |
7 | ```js
8 | var foo = {
9 | bar: "baz",
10 | qux: "quux",
11 | };
12 | ```
13 |
14 | ## Rule Details
15 |
16 | This rule is aimed at detecting trailing commas in object literals. As such, it will warn whenever it encounters a trailing comma in an object literal.
17 |
18 | The following are considered problems:
19 |
20 | ```js
21 | var foo = {
22 | bar: "baz",
23 | qux: "quux",
24 | };
25 |
26 | var arr = [1,2,];
27 |
28 | foo({
29 | bar: "baz",
30 | qux: "quux",
31 | });
32 | ```
33 |
34 | The following patterns are not considered problems:
35 |
36 | ```js
37 | var foo = {
38 | bar: "baz",
39 | qux: "quux"
40 | };
41 |
42 | var arr = [1,2];
43 |
44 | foo({
45 | bar: "baz",
46 | qux: "quux"
47 | });
48 | ```
49 |
50 | ## When Not To Use It
51 |
52 | If your code will not be run in IE8 or below (a NodeJS application, for example) and you'd prefer to allow trailing commas, turn this rule off.
53 |
--------------------------------------------------------------------------------
/packages/eslint-config-eslint/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Converts YAML file into JSON.
3 | * @author Nicholas C. Zakas
4 | * @copyright 2015 Nicholas C. Zakas. All rights reserved.
5 | * See LICENSE file in root directory for full license.
6 | */
7 | "use strict";
8 |
9 | //------------------------------------------------------------------------------
10 | // Requirements
11 | //------------------------------------------------------------------------------
12 |
13 | var fs = require("fs"),
14 | path = require("path"),
15 | yaml = require("js-yaml");
16 |
17 | //------------------------------------------------------------------------------
18 | // Bootstrapping
19 | //------------------------------------------------------------------------------
20 |
21 | var filePath = path.resolve(__dirname, "./default.yml"),
22 | config;
23 |
24 | try {
25 | config = yaml.safeLoad(fs.readFileSync(filePath, "utf8")) || {};
26 | } catch (e) {
27 | console.error("Error reading YAML file: " + filePath);
28 | e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
29 | throw e;
30 | }
31 |
32 |
33 | //------------------------------------------------------------------------------
34 | // Public Interface
35 | //------------------------------------------------------------------------------
36 |
37 | module.exports = config;
38 |
--------------------------------------------------------------------------------
/lib/rules/no-const-assign.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview A rule to disallow modifying variables that are declared using `const`
3 | * @author Toru Nagashima
4 | * @copyright 2015 Toru Nagashima. All rights reserved.
5 | */
6 |
7 | "use strict";
8 |
9 | var astUtils = require("../ast-utils");
10 |
11 | //------------------------------------------------------------------------------
12 | // Rule Definition
13 | //------------------------------------------------------------------------------
14 |
15 | module.exports = function(context) {
16 |
17 | /**
18 | * Finds and reports references that are non initializer and writable.
19 | * @param {Variable} variable - A variable to check.
20 | * @returns {void}
21 | */
22 | function checkVariable(variable) {
23 | astUtils.getModifyingReferences(variable.references).forEach(function(reference) {
24 | context.report(
25 | reference.identifier,
26 | "`{{name}}` is constant.",
27 | {name: reference.identifier.name});
28 | });
29 | }
30 |
31 | return {
32 | "VariableDeclaration": function(node) {
33 | if (node.kind === "const") {
34 | context.getDeclaredVariables(node).forEach(checkVariable);
35 | }
36 | }
37 | };
38 |
39 | };
40 |
41 | module.exports.schema = [];
42 |
--------------------------------------------------------------------------------
/lib/rules/no-restricted-syntax.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Rule to flag use of certain node types
3 | * @author Burak Yigit Kaya
4 | * @copyright 2015 Burak Yigit Kaya. All rights reserved.
5 | */
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Rule Definition
10 | //------------------------------------------------------------------------------
11 |
12 | var nodeTypes = require("espree").Syntax;
13 |
14 | module.exports = function(context) {
15 | /**
16 | * Generates a warning from the provided node, saying that node type is not allowed.
17 | * @param {ASTNode} node The node to warn on
18 | * @returns {void}
19 | */
20 | function warn(node) {
21 | context.report(node, "Using \"{{type}}\" is not allowed.", node);
22 | }
23 |
24 | return context.options.reduce(function(result, nodeType) {
25 | result[nodeType] = warn;
26 |
27 | return result;
28 | }, {});
29 |
30 | };
31 |
32 | module.exports.schema = {
33 | "type": "array",
34 | "items": [
35 | {
36 | "enum": [0, 1, 2]
37 | },
38 | {
39 | "enum": Object.keys(nodeTypes).map(function(k) {
40 | return nodeTypes[k];
41 | })
42 | }
43 | ],
44 | "uniqueItems": true,
45 | "minItems": 1
46 | };
47 |
--------------------------------------------------------------------------------
/lib/load-rules.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Module for loading rules from files and directories.
3 | * @author Michael Ficarra
4 | */
5 |
6 | "use strict";
7 |
8 | //------------------------------------------------------------------------------
9 | // Requirements
10 | //------------------------------------------------------------------------------
11 |
12 | var fs = require("fs"),
13 | path = require("path");
14 |
15 | //------------------------------------------------------------------------------
16 | // Public Interface
17 | //------------------------------------------------------------------------------
18 |
19 | /**
20 | * Load all rule modules from specified directory.
21 | * @param {String} [rulesDir] Path to rules directory, may be relative. Defaults to `lib/rules`.
22 | * @returns {Object} Loaded rule modules by rule ids (file names).
23 | */
24 | module.exports = function(rulesDir) {
25 | if (!rulesDir) {
26 | rulesDir = path.join(__dirname, "rules");
27 | } else {
28 | rulesDir = path.resolve(process.cwd(), rulesDir);
29 | }
30 |
31 | var rules = Object.create(null);
32 | fs.readdirSync(rulesDir).forEach(function(file) {
33 | if (path.extname(file) !== ".js") {
34 | return;
35 | }
36 | rules[file.slice(0, -3)] = path.join(rulesDir, file);
37 | });
38 | return rules;
39 | };
40 |
--------------------------------------------------------------------------------
/docs/rules/no-arrow-condition.md:
--------------------------------------------------------------------------------
1 | # Disallow arrow functions where a condition is expected (no-arrow-condition)
2 |
3 | Arrow functions (`=>`) are similar in syntax to some comparison operators (`>`, `<`, `<=`, and `>=`). This rule warns against using the arrow function syntax in places where a condition is expected. Even if the arguments of the arrow function are wrapped with parens, this rule still warns about it.
4 |
5 | Here's an example where the usage of `=>` is most likely a typo:
6 |
7 | ```js
8 | // This is probably a typo
9 | if (a => 1) {}
10 | // And should instead be
11 | if (a >= 1) {}
12 | ```
13 |
14 | There are also cases where the usage of `=>` can be ambiguous and should be rewritten to more clearly show the author's intent:
15 |
16 | ```js
17 | // The intent is not clear
18 | var x = a => 1 ? 2 : 3
19 | // Did the author mean this
20 | var x = function (a) { return a >= 1 ? 2 : 3 }
21 | // Or this
22 | var x = a <= 1 ? 2 : 3
23 | ```
24 |
25 | ## Rule Details
26 |
27 | The following patterns are considered warnings:
28 |
29 | ```js
30 | /*eslint no-arrow-condition: 2*/
31 | /*eslint-env es6*/
32 |
33 | if (a => 1) {}
34 | while (a => 1) {}
35 | for (var a = 1; a => 10; a++) {}
36 | a => 1 ? 2 : 3
37 | (a => 1) ? 2 : 3
38 | var x = a => 1 ? 2 : 3
39 | var x = (a) => 1 ? 2 : 3
40 | ```
41 |
42 | ## Related Rules
43 |
44 | * [arrow-parens](arrow-parens.md)
45 |
--------------------------------------------------------------------------------
/docs/rules/no-invalid-regexp.md:
--------------------------------------------------------------------------------
1 | # Disallow Invalid Regular Expressions (no-invalid-regexp)
2 |
3 | This rule validates string arguments passed to the `RegExp` constructor.
4 |
5 | ## Rule Details
6 |
7 | The following patterns are considered problems:
8 |
9 | ```js
10 | /*eslint no-invalid-regexp: 2*/
11 |
12 | RegExp('[') /*error Invalid regular expression: /[/: Unterminated character class*/
13 |
14 | RegExp('.', 'z') /*error Invalid flags supplied to RegExp constructor 'z'*/
15 |
16 | new RegExp('\\') /*error Invalid regular expression: /\/: \ at end of pattern*/
17 | ```
18 |
19 | The following patterns are not considered problems:
20 |
21 | ```js
22 | /*eslint no-invalid-regexp: 2*/
23 |
24 | RegExp('.')
25 |
26 | new RegExp
27 |
28 | this.RegExp('[')
29 | ```
30 |
31 | ## New ECMAScript 6 Flags
32 |
33 | ECMAScript 6 adds the "u" ([unicode](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.unicode)) and "y" ([sticky](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.sticky)) flags. You can enable these to be recognized as valid by adding the following to your `.eslintrc` file:
34 |
35 | ```json
36 | "ecmaFeatures": {
37 | "regexYFlag": true,
38 | "regexUFlag": true
39 | }
40 | ```
41 |
42 | ## Further Reading
43 |
44 | * [Annotated ES5 §7.8.5 - Regular Expression Literals](http://es5.github.io/#x7.8.5)
45 |
--------------------------------------------------------------------------------