Skip to content

Instantly share code, notes, and snippets.

@boneskull
Last active January 28, 2017 08:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boneskull/9078fb5cbc943236fd58 to your computer and use it in GitHub Desktop.
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
{
"extends": "semistandard",
"parser": "babel-eslint",
"plugins": [
"lodash3",
"no-class",
"mocha-only",
"prototype-chain"
],
"rules": {
"space-before-function-paren": 0,
"arrow-parens": [
1,
"as-needed"
]
}
}
'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');
{
"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"
}
@boneskull
Copy link
Author

fabulously horrible, but seems to "work" until ESLint changes a couple lines of code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment