Giter VIP home page Giter VIP logo

eslint-myrules-manager's Introduction

eslint-myrules-manager

Manager for your ESLint rules. The goal is to have your favorite rules in one place to use everywhere. No rules are included in this module, you must provide your own. You can see an example at eslint-myrules. It copies your rules in your project and can be used to lint your project as well. The goal of copying the rules is to allow IDE integration to find your rules, like SublimeLinter for instance.

Installation

$ npm install eslint-myrules-manager --save-dev

Config file

You can configure the tool in your package.json or package.json5 or in a .myrulesrc file. Currently supported options

{
  "eslint-myrules": {
    "targets": {
      "global": String|String[], // List of backend folders to lint
      "yourTarget": String|String[]
    },
    "modifiers": {},
    "extraRules": {
      "global": {
        // any valid .eslintrc config
      }
    },
    "options": String // extra options to pass to eslint
    "mergeGlobal": String|String[]
  }
}
  • eslint-myrules: the name of this project. If you rename the project, make sure to change this
    • targets: list of different targets for your rules. Can be empty if you simply want 1 set of rules. However, very useful if you want to override some rules.
    • modifiers: see MODIFIERS
    • extraRules: Include any project specific configuration you want to pass to eslint.
    • mergeGlobal: list of targets you want to merge with global rules to be placed at the root of your project. Useful when your whole project needs to be lint with a specific target.

You can see an example at .myrulesrc

Linting

You can run this tool on your project to lint your sources. It uses ESLint for code style and error check. See ESLint for details about the rules.

Usage

No binary is provided with this library. You have to make your own, but the api comes with a command line parser. See cliWrapper for an example on how to correctly execute the cli.

$ eslint-myrules lint -h
  Usage: lint [options] [...global_folders]

  lint your project

  Options:

    -h, --help                                    output usage information
    -c, --config <config_path[.js|.json|.json5]>  Path to the config file

The tool first copies current rules into the root of your project and in every target folders. It then runs the linter and outputs errors.

  • --config: uses a different config file than package.json. It can be a normal js file exporting the config object.
  • global_folders: space separated list of folder to run the linter on. It does not copy any extra linter rules. Can be used without any config file present.

Example

// Config in package.json
"eslint-myrules: {
  "targets": {
    "backend": ["app", "lib"],
    "frontend": ["js"]
  }
},
"scripts": {
  "lint": "eslint-myrules lint bin index.js"
}
$ npm run lint

This will copy the rules

  • backend rules to folders app and lib
  • frontend rules to folder js
  • global rules to the root of your project

This will execute the linter in

  • backend folders app and lib
  • frontend folder js
  • folder bin and file index.js

Api

  • execute: (myrules, argv) => void
    • myrules: Configuration of your rules, see below for example
    • argv: cli options, should come directly from process.argv
  • utils: Object
    • mergeConfigs: (config1, config2) => config; Merge 2 eslint configuration object together and return the result.

Configuration object

{
  targetsPath: {
    // change path to actual location
    global: path.resolve(__dirname, "../rules/global.eslintrc"),
    // List all other targets and their respective rules file
    ...otherTarget: pathToYourRuleFile
  },
  modifiers: {
    // List all targets with modifiers
    targetName: {
      // list all possible modifiers
      modifierName: function(modifierConfig, rules, target) => updatedRules
    }
  },
  // Options to pass to ESLint
  eslintOptions: "--ext .js --ext .jsx" //default value,
  // Default configuration of your rules to be merged with given config
  defaultConfig: {}
}

Example

{
  targetsPath: {
    global: path.resolve(__dirname, "../rules/global.eslintrc"),
    frontend: path.resolve(__dirname, "../rules/frontend.eslintrc"),
    backend: path.resolve(__dirname, "../rules/backend.eslintrc")
  },
  modifiers: {
    frontend: {
      react: require("./modifiers/react")
    }
  },
  eslintOptions: "--ext .js --no-color",
  defaultConfig: {
    targets: {
      global: ["lib"]
    },
    modifiers: {
      react: true // can be anything, will be passed directly to your function
    }
  }
}

eslint-myrules-manager's People

Contributors

cellule avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.