├── .eslintrc.json ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── bin └── eslint.js ├── lib ├── get-bin-eslint-js.js └── get-local-eslint.js └── package.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint", "plugin:node/recommended"], 3 | "plugins": ["node"] 4 | } 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | jobs: 10 | lint: 11 | name: Lint 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Setup Node.js 16 | uses: actions/setup-node@v1 17 | with: 18 | node-version: '12.x' 19 | - name: Install dependencies 20 | run: npm install 21 | - name: Lint files 22 | run: npm run lint 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /test.js 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :warning: This package is no longer necessary. Use the built-in [`npx`](https://docs.npmjs.com/cli/v8/commands/npx) command instead. 2 | 3 | ```sh 4 | npm install --save-dev eslint 5 | npx eslint src 6 | ``` 7 | 8 | --- 9 | 10 | # eslint-cli 11 | 12 | [![npm version](https://img.shields.io/npm/v/eslint-cli.svg)](https://www.npmjs.com/package/eslint-cli) 13 | [![Downloads/month](https://img.shields.io/npm/dm/eslint-cli.svg)](http://www.npmtrends.com/eslint-cli) 14 | [![Dependency Status](https://david-dm.org/eslint/eslint-cli.svg)](https://david-dm.org/eslint/eslint-cli) 15 | 16 | The local [ESLint] executor. 17 | 18 | ## ⤴️ Motivation 19 | 20 | ESLint recommends that we install ESLint into project-local rather than global. 21 | 22 | $ npm install --save-dev eslint 23 | 24 | In that case, there are many merits, but `eslint` CLI command is not available. 25 | 26 | # This is error: 27 | $ eslint src 28 | 29 | # So you have to use: 30 | $ ./node_modules/.bin/eslint src 31 | 32 | It's inconvenient a bit. This package gives you `eslint` CLI command which runs local installed ESLint. 33 | 34 | ## 💿 Installation 35 | 36 | Use [npm] to install. 37 | 38 | $ npm install -g eslint-cli 39 | 40 | **Note:** 41 | 42 | - The `eslint` package must not be installed into global. 43 | - This package must be installed into global. 44 | 45 | ## 📖 Usage 46 | 47 | First, install the `eslint` package into project-local. 48 | 49 | $ npm install --save-dev eslint 50 | 51 | Next, use `eslint` CLI command. 52 | 53 | $ eslint src 54 | 55 | The command runs the global-installed `eslint-cli`, then it finds and runs the local-installed `eslint`. 56 | 57 | That's all. Enjoy! 58 | 59 | ## 📰 Change logs 60 | 61 | - See [GitHub releases](https://github.com/eslint/eslint-cli/releases) 62 | 63 | ## 🍻 Contributing 64 | 65 | Contributing is welcome! 66 | 67 | Please use issues/PRs of GitHub. 68 | 69 | [eslint]: http://eslint.org/ 70 | [npm]: https://www.npmjs.com/ 71 | -------------------------------------------------------------------------------- /bin/eslint.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /** 3 | * @author Toru Nagashima 4 | * See LICENSE file in root directory for full license. 5 | */ 6 | "use strict"; 7 | 8 | const debug = require("debug")("eslint-cli"); 9 | const debugMode = process.argv.indexOf("--debug") !== -1; 10 | const cwd = process.cwd(); 11 | 12 | if (debugMode) { 13 | require("debug").enable("eslint-cli"); 14 | } 15 | 16 | debug("START", process.argv); 17 | debug("ROOT", cwd); 18 | 19 | const binPath = require("../lib/get-local-eslint")(cwd) || require("../lib/get-bin-eslint-js")(cwd); 20 | 21 | if (binPath !== null) { 22 | require(binPath); 23 | } else { 24 | // eslint-disable-next-line no-console 25 | console.error(` 26 | Could not find local ESLint. 27 | Please install ESLint by 'npm install --save-dev eslint'. 28 | `); 29 | process.exitCode = 1; 30 | } 31 | -------------------------------------------------------------------------------- /lib/get-bin-eslint-js.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Toru Nagashima 3 | * See LICENSE file in root directory for full license. 4 | */ 5 | "use strict"; 6 | 7 | const fs = require("fs"); 8 | const path = require("path"); 9 | const debug = require("debug")("eslint-cli"); 10 | 11 | /** 12 | * Finds and tries executing "./bin/eslint.js". 13 | * 14 | * This is useful to ESLint contributors. 15 | * ESLint's repository has "./bin/eslint.js". 16 | * 17 | * @param {string} basedir - A path of the directory that it starts searching. 18 | * @returns {string|null} The path of "./bin/eslint.js" 19 | */ 20 | module.exports = basedir => { 21 | let dir = basedir; 22 | let prevDir = dir; 23 | 24 | do { 25 | const binPath = path.join(dir, "bin", "eslint.js"); 26 | 27 | if (fs.existsSync(binPath)) { 28 | debug("FOUND '%s'", binPath); 29 | return binPath; 30 | } 31 | debug("NOT FOUND '%s'", binPath); 32 | 33 | // Finish if package.json is found. 34 | if (fs.existsSync(path.join(dir, "package.json"))) { 35 | break; 36 | } 37 | 38 | // Go to next. 39 | prevDir = dir; 40 | dir = path.resolve(dir, ".."); 41 | } 42 | while (dir !== prevDir); 43 | 44 | debug("NOT FOUND './bin/eslint.js'"); 45 | return null; 46 | }; 47 | -------------------------------------------------------------------------------- /lib/get-local-eslint.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Toru Nagashima 3 | * See LICENSE file in root directory for full license. 4 | */ 5 | "use strict"; 6 | 7 | const debug = require("debug")("eslint-cli"); 8 | const resolve = require("resolve"); 9 | 10 | /** 11 | * Finds and tries executing a local eslint module. 12 | * 13 | * @param {string} basedir - A path of the directory that it starts searching. 14 | * @returns {string|null} The path of a local eslint module. 15 | */ 16 | module.exports = basedir => { 17 | try { 18 | const binPath = resolve.sync("eslint/bin/eslint.js", { basedir }); 19 | 20 | debug("FOUND '%s'", binPath); 21 | return binPath; 22 | } catch (err) { 23 | if ((err && err.code) !== "MODULE_NOT_FOUND") { 24 | throw err; 25 | } 26 | debug("NOT FOUND 'eslint/bin/eslint.js'"); 27 | return null; 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-cli", 3 | "version": "1.1.1", 4 | "description": "The local eslint executor.", 5 | "engines": { 6 | "node": ">=4.0.0" 7 | }, 8 | "files": [ 9 | "bin", 10 | "lib" 11 | ], 12 | "bin": { 13 | "eslint": "bin/eslint.js", 14 | "eslint-cli": "bin/eslint.js" 15 | }, 16 | "scripts": { 17 | "postversion": "git push && git push --tags", 18 | "lint": "eslint bin lib" 19 | }, 20 | "dependencies": { 21 | "debug": "^3.1.0", 22 | "resolve": "^1.3.3" 23 | }, 24 | "devDependencies": { 25 | "eslint": "^4.19.1", 26 | "eslint-config-eslint": "^4.0.0", 27 | "eslint-plugin-node": "^6.0.1" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/eslint/eslint-cli.git" 32 | }, 33 | "keywords": [ 34 | "eslint", 35 | "cli" 36 | ], 37 | "author": "Toru Nagashima", 38 | "license": "MIT", 39 | "bugs": { 40 | "url": "https://github.com/eslint/eslint-cli/issues" 41 | }, 42 | "homepage": "https://github.com/eslint/eslint-cli#readme" 43 | } 44 | --------------------------------------------------------------------------------