Last active
January 28, 2017 08:42
-
-
Save boneskull/9078fb5cbc943236fd58 to your computer and use it in GitHub Desktop.
monkeypatch eslint from config to avoid peerDependencies; just "npm install eslint eslint-config-your-config" and the rest happens by evil magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extends": "semistandard", | |
"parser": "babel-eslint", | |
"plugins": [ | |
"lodash3", | |
"no-class", | |
"mocha-only", | |
"prototype-chain" | |
], | |
"rules": { | |
"space-before-function-paren": 0, | |
"arrow-parens": [ | |
1, | |
"as-needed" | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var pkg = require('./package.json'); | |
var dependencies = Object.keys(pkg.dependencies); | |
var pkgName = pkg.name; | |
var path = require('path'); | |
// monkeypatch from hell makes eslint load all of a config's | |
// dependencies. | |
function patchRequire(original, filepath) { | |
return function (name) { | |
var idx = dependencies.indexOf(name); | |
if (idx > -1) { | |
name = path.join(__dirname, 'node_modules', name); | |
return original(name); | |
} | |
if (path.isAbsolute(name)) { | |
return original(name); | |
} | |
if (name === pkgName) { | |
return module.exports; | |
} | |
if (name.charAt(0) === '.') { | |
return original(path.join(path.dirname(filepath), name)); | |
} | |
return original(path.join(path.dirname(filepath), | |
'..', | |
'..', | |
'node_modules', | |
name)); | |
}; | |
} | |
// TODO assertions that these are correct, or otherwise scan for the | |
// files in question. | |
var cliEngine = module.parent.parent.parent; | |
var configFile = cliEngine.children[5].children[0]; | |
var configFileRequire = configFile.require; | |
var cliEngineRequire = cliEngine.require; | |
cliEngine.require = patchRequire(cliEngineRequire, cliEngine.filename); | |
configFile.require = patchRequire(configFileRequire, configFile.filename); | |
module.exports = require('./eslintrc.json'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"babel-eslint": "^4.1.6", | |
"eslint-config-semistandard": "^5.0.0", | |
"eslint-config-standard": "^4.4.0", | |
"eslint-plugin-lodash3": "^0.3.0", | |
"eslint-plugin-mocha-only": "0.0.3", | |
"eslint-plugin-no-class": "^0.1.0", | |
"eslint-plugin-prototype-chain": "boneskull/eslint-plugin-prototype-chain", | |
"eslint-plugin-standard": "^1.3.1" | |
}, | |
"main": "index.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fabulously horrible, but seems to "work" until ESLint changes a couple lines of code