spilgames / javascript-styleguide

The home of the Spil Games JavaScript Style Guide, and related content.
http://www.spilgames.com
0 stars 0 forks source link

Proposal: Standardized lint configuration #2

Open guidokessels opened 10 years ago

guidokessels commented 10 years ago

Hi all,

To make it easier for developers to write code that conforms to the JavaScript styleguide and avoid common errors/bad practices, I'd like to propose a set of tools that allows everyone to automatically validate their code.

As a start I'd like to propose a standardized ESLint configuration.

ESLint is a tool for identifying and reporting on patterns found in JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:

ESLint is very easy to integrate into any JavaScript project via grunt-eslint.

As with every linting tool, ESLint will hurt your feelings. Most, if not all, of your files will trigger warnings. As with every new standard, this is to be expected.

However, please don't refute this proposal on that basis alone. Instead, think about the advantages that a clear, consistent codebase will bring us, and how this will allow us to spot bad code much earlier in the development cycle.

guidokessels commented 10 years ago

Here's the ESLint configuration I'd like to propose. Please play around with it in your projects and see if you like the results.

I've tried to make it match our styleguide as much as possible. If you spot any inconsistencies please leave a comment.

You can find a description of each rule here.

{
    "env": {
        "browser"   : true,
        "node"      : false,
        "amd"       : true
    },
    "rules": {
        "no-cond-assign"             : 2,
        "no-console"                 : 2,
        "no-comma-dangle"            : 2,
        "no-underscore-dangle"       : 0,
        "no-control-regex"           : 2,
        "no-debugger"                : 2,
        "no-dupe-keys"               : 2,
        "no-empty"                   : 2,
        "no-empty-class"             : 2,
        "no-ex-assign"               : 2,
        "no-extra-parens"            : 0,
        "no-extra-semi"              : 2,
        "no-func-assign"             : 0,
        "no-invalid-regexp"          : 2,
        "no-negated-in-lhs"          : 0,
        "no-obj-calls"               : 2,
        "no-unreachable"             : 2,
        "use-isnan"                  : 2,

        "block-scoped-var"           : 0,
        "complexity"                 : 0,
        "curly"                      : 2,
        "dot-notation"               : 0,
        "eqeqeq"                     : 2,
        "guard-for-in"               : 2,
        "no-alert"                   : 2,
        "no-caller"                  : 2,
        "no-eval"                    : 2,
        "no-extend-native"           : 0,
        "no-floating-decimal"        : 2,
        "no-native-reassign"         : 2,
        "no-new"                     : 2,
        "no-new-func"                : 2,
        "no-octal"                   : 0,
        "no-octal-escape"            : 0,
        "no-with"                    : 2,
        "no-return-assign"           : 2,
        "no-self-compare"            : 2,
        "no-eq-null"                 : 2,
        "no-multi-str"               : 0,
        "no-loop-func"               : 2,
        "no-empty-label"             : 2,
        "no-unused-expressions"      : 2,
        "no-script-url"              : 2,
        "no-proto"                   : 2,
        "no-iterator"                : 2,
        "no-else-return"             : 2,
        "no-redeclare"               : 2,
        "no-div-regex"               : 2,
        "wrap-iife"                  : 2,

        "no-global-strict"           : 2,
        "strict"                     : 1,

        "no-catch-shadow"            : 2,
        "no-delete-var"              : 2,
        "no-label-var"               : 2,
        "no-shadow"                  : 2,
        "no-shadow-restricted-names" : 2,
        "no-undef"                   : 2,
        "no-undef-init"              : 2,
        "no-unused-vars"             : 2,
        "no-use-before-define"       : 2,

        "brace-style"                : 2,
        "camelcase"                  : 2,
        "consistent-this"            : 0,
        "func-style"                 : [2, "declaration"],
        "new-cap"                    : 2,
        "new-parens"                 : 2,
        "no-mixed-requires"          : 0,
        "no-nested-ternary"          : 2,
        "no-spaced-func"             : 2,
        "no-ternary"                 : 0,
        "no-wrap-func"               : 2,
        "quotes"                     : [2, "single"],
        "quote-props"                : 0,
        "semi"                       : 2,
        "sort-vars"                  : 0,
        "space-infix-ops"            : 2,
        "space-return-throw-case"    : 2,
        "space-unary-word-ops"       : 2,
        "max-nested-callbacks"       : 0,
        "one-var"                    : 2,
        "wrap-regex"                 : 0,

        "max-depth"                  : 0,
        "max-len"                    : [1, 100, 4],
        "max-params"                 : 0,
        "max-statements"             : 0,
        "no-bitwise"                 : 0,
        "no-plusplus"                : 0
    }
}

Usage

  1. Copy-paste the config above into a new file and save as .eslintrc in your project root
  2. Either install ESLint globally and run from command-line (npm install -g eslint) or use it with Grunt (grunt-eslint)
stefanooldeman commented 10 years ago

I don't know if "plugabble" is a good thing for a tool that should check if code complies with standards.. Because if you can change the checks, what is left of the standards (http://xkcd.com/927/)? I mean its not just what we think is good but rather lets go for the community standard and make it work for us.

what about using either JSLint or JSHint and have exceptions on those. with the header comments in JS files?

I can try eslint and see how it works. but I don't see much benefit now. I just have jslint installed in vim and it works, always on any file..

iLaurens commented 10 years ago

+1. How do you see this being used? I think it should run as a pre-commit hook to ensure we keep ourselves to the standards.