├── .gitignore ├── package.json ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-project-relative", 3 | "version": "0.3.0", 4 | "description": "run the right eslint for your project from flycheck or syntastic", 5 | "main": "index.js", 6 | "bin": { 7 | "eslint-project-relative": "./index.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "keywords": [ 13 | "eslint", 14 | "relative", 15 | "flycheck", 16 | "syntastic" 17 | ], 18 | "author": "Jake Teton-Landis", 19 | "license": "ISC", 20 | "dependencies": { 21 | "kexec": "2.0.2", 22 | "resolve": "1.1.7", 23 | "shelljs": "0.6.0", 24 | "yargs": "3.32.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eslint-project-relative 2 | 3 | what, you want to run ESlint in your $EDITOR, but it keeps picking the wrong 4 | ESLint? Or you don't even have ESLint installed globally? 5 | 6 | That sucks. That sucks a lot. 7 | 8 | use `eslint-project-relative` instead. It will try to find the "right" eslint 9 | executable for the files you want to lint. 10 | 11 | It does this by using node's own resolve algorothm based on the file arguments 12 | you pass to eslint-project-relative. If you don't pass any file args, we'll just 13 | use the present working directory instead. 14 | 15 | After we find an eslint, we use `POSIX exec` to run it directly, passing through 16 | all arguments, etc 17 | 18 | ## usage 19 | 20 | first, install globally. 21 | 22 | ``` 23 | npm install -g eslint-project-relative 24 | ``` 25 | 26 | Then, configure editor: 27 | 28 | ### syntastic (vim) 29 | ```vimscript 30 | let g:syntastic_javascript_eslint_exec = 'eslint-project-relative' 31 | ``` 32 | 33 | ### flycheck (emacs) 34 | ```elisp 35 | (setq flycheck-javascript-eslint-executable "eslint-project-relative") 36 | ``` 37 | 38 | ### other editors 39 | 40 | PRS WELCOME!!!!1 update my readme pls. 41 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var kexec = require('kexec') 4 | var yargs = require('yargs') 5 | var path = require('path') 6 | var shell = require('shelljs') 7 | var resolve = require('resolve') 8 | var fs = require('fs') 9 | 10 | function getFileArgs() { 11 | return yargs.argv._ 12 | } 13 | 14 | function eslintNearFile(file) { 15 | if (file[0] !== '/') { 16 | file = path.join(shell.pwd(), file) 17 | } 18 | 19 | var dir = shell.test('-d', file) 20 | ? file 21 | : path.dirname(file) 22 | 23 | // resolve eslint 24 | try { 25 | var resolvedLocation = resolve.sync('eslint/package.json', { basedir: dir }) 26 | var eslintPackageDir = path.dirname(resolvedLocation) 27 | var eslintPackage = JSON.parse(fs.readFileSync(resolvedLocation)) 28 | return path.join(eslintPackageDir, eslintPackage.bin.eslint) 29 | } catch (err) { 30 | shell.echo('could not find eslint near ' + file) 31 | return shell.which('eslint') 32 | } 33 | } 34 | 35 | function main() { 36 | var options = getFileArgs() 37 | var relativeFrom = options.length === 0 38 | ? shell.pwd() 39 | : options[0] 40 | var exe = eslintNearFile(relativeFrom) 41 | if (exe) { 42 | // shell.echo("using eslint at " + exe) 43 | kexec(exe, process.argv.slice(2)) 44 | } else { 45 | shell.echo('eslint not found') 46 | process.exit(1) 47 | } 48 | } 49 | 50 | main() 51 | --------------------------------------------------------------------------------