Code Monkey home page Code Monkey logo

eslint-lockdown's Introduction

eslint-lockdown

generate an .eslintrc against a legacy codebase

usage

$ npm i -g eslint-lockdown
$ eslint-lockdown

eslint-lockdown will generate an .eslintrc to utilize eslint against a legacy codebase. It reads in your (optional) current .eslintrc file and generates a new .eslintrc with failing rules marked as warn. This allows you to "put a stake in the ground" to prevent your code getting worse, utilizing eslint as part of your build process without halting development.

By default, eslint-lockdown will overwrite the .eslintrc file. To preview the results without overwriting:

$ eslint-lockdown --debug

example

This snippet, foo.js:

module.exports = function() {
    var unused = true;
    console.log("foobar");
}

violates many eslint:recommended rules:

$ eslint foo.js

/foo/bar/foo.js
  1:1  error  "module" is not defined             no-undef
  2:9  error  "unused" is defined but never used  no-unused-vars
  3:5  error  Unexpected console statement        no-console
  3:5  error  "console" is not defined            no-undef

✖ 4 problems (4 errors, 0 warnings)

Running eslint-lockdown, we would generate an .eslintrc file to make eslint pass:

{
    "extends": "eslint:recommended",
    "rules": {
        "no-undef": [ 1 ],
        "no-unused-vars": [ 1 ],
        "no-console": [ 1 ]
    }
}

After generating the new file, eslint will pass with warnings:

$ eslint .

/Users/john/mysrc/weisjohn/scratch/eslint_lockdown/index.js
  1:1  warning  "module" is not defined             no-undef
  2:9  warning  "unused" is defined but never used  no-unused-vars
  3:5  warning  Unexpected console statement        no-console
  3:5  warning  "console" is not defined            no-undef

✖ 4 problems (0 errors, 4 warnings)

library

If you want to further wrangle the configuration, you can use eslint-lockdown as a node library:

var lockdown = require('eslint-lockdown');

lockdown(__dirname, function(err, config) {
    if (err) return console.error(err);
    console.log(config);
});

eslint-lockdown's People

Contributors

weisjohn avatar

Stargazers

Anne Thorpe avatar Ian VanSchooten avatar  avatar

Watchers

 avatar James Cloos avatar

eslint-lockdown's Issues

pretty output

The simple JSON formatter produces results that are expanded too much. see diff on #2

retain arguments for rules that are specified

When merging the rules, we should retain the arguments for those values which are replaced. Consider this diff:

$ gdc
diff --git a/.eslintrc b/.eslintrc
index cdfe049..bc96136 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,10 +1,33 @@
 {
     "rules": {
-        "indent": [ 2, 4 ],
-        "quotes": [ 2, "single" ],
-        "linebreak-style": [ 2, "unix" ],
-        "semi": [ 2, "always" ],
-        "comma-dangle": [ 0 ]
+        "indent": [
+            1
+        ],
+        "quotes": [
+            1
+        ],
+        "linebreak-style": [
+            2,
+            "unix"
+        ],
+        "semi": [
+            1
+        ],
+        "comma-dangle": [
+            0
+        ],
+        "no-unused-vars": [
+            1
+        ],
+        "no-console": [
+            1
+        ],
+        "no-undef": [
+            1
+        ],
+        "no-redeclare": [
+            1
+        ]
     },
     "env": {
         "es6": true,
@@ -12,4 +35,4 @@
         "node": true
     },
     "extends": "eslint:recommended"
-}
+}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.