-
Notifications
You must be signed in to change notification settings - Fork 94
Do not raise error on unsupported plugins #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4ebe83a
69ae42e
900b717
8007e08
f86331d
a8a48b8
c77123e
bed9979
d656886
db6a421
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
rules: {}, | ||
configs: { | ||
recommended: {} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
'use strict'; | ||
var meld = require('meld'); | ||
var docs = require('./docs'); | ||
var Config = require("eslint/lib/config"); | ||
var ConfigUpgrader = require('./config_upgrader'); | ||
|
||
var supportedPlugins = ['react', 'babel']; | ||
|
||
module.exports = function patcher(eslint) { | ||
|
||
meld.around(eslint.CLIEngine, 'loadPlugins', function(joinPoint) { | ||
var pluginNames = joinPoint.args[0]; | ||
var filteredPluginNames = pluginNames.filter(function(pluginName) { | ||
return supportedPlugins.indexOf(pluginName) >= 0; | ||
}); | ||
return joinPoint.proceed(filteredPluginNames); | ||
}); | ||
|
||
meld.around(eslint.CLIEngine, 'addPlugin', function() { | ||
return; | ||
}); | ||
|
||
// meld.around(eslint.CLIEngine.Config, 'loadPackage', function(joinPoint) { | ||
// var filePath = joinPoint.args[0]; | ||
// if (filePath.match(/^eslint-config-airbnb.*/)) { | ||
// return joinPoint.proceed(); | ||
// } else { | ||
// return {}; | ||
// } | ||
// }); | ||
"use strict"; | ||
|
||
const Plugins = require("eslint/lib/config/plugins"); | ||
const ModuleResolver = require("eslint/lib/util/module-resolver"); | ||
|
||
const ConfigFile = require("eslint/lib/config/config-file"); | ||
|
||
const Config = require("eslint/lib/config"); | ||
const ConfigUpgrader = require("./config_upgrader"); | ||
|
||
module.exports = function patch() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was removed because this hook doesn't ever actually fire? (I think I saw another comment you made about this) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxjacobson The function is only implemented on eslint 1.9 and lower, so my understanding is it wasn't doing anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It never fired on my tests... |
||
|
||
const skippedModules = []; | ||
function warnModuleNotSupported(name) { | ||
if(skippedModules.indexOf(name) < 0) { | ||
skippedModules.push(name); | ||
console.error(`Module not supported: ${name}`); | ||
} | ||
} | ||
|
||
const resolve = ModuleResolver.prototype.resolve; | ||
ModuleResolver.prototype.resolve = function(name, path) { | ||
try { | ||
return resolve.apply(this, [name, path]); | ||
} catch(e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should log something here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxjacobson Any suggestions about the message? I am feeling it would just duplicate what we do at line 34. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using the same message sounds fine. Are you saying it's already being printed? I didn't see it when doing local QA, so I thought it wasn't included there |
||
warnModuleNotSupported(name); | ||
return `${__dirname}/empty-plugin.js`; | ||
} | ||
}; | ||
|
||
Plugins.loadAll = function(pluginNames) { | ||
const loadedPlugins = Object.keys(Plugins.getAll()); | ||
if(loadedPlugins.length > 0) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a wild guess, but it feels like this early return is the culprit of #214. If Maybe we can monkey patch this again with only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other alternative would be to only patch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucasmazza On it! :) |
||
} | ||
|
||
for(const index in pluginNames) { | ||
const name = pluginNames[index]; | ||
try { | ||
|
||
Plugins.load(name); | ||
|
||
} catch(e) { | ||
warnModuleNotSupported(`eslint-plugin-${name}`); | ||
} | ||
} | ||
}; | ||
|
||
const originalGetConfig = Config.prototype.getConfig; | ||
Config.prototype.getConfig = function(filePath) { | ||
|
@@ -37,7 +54,5 @@ module.exports = function patcher(eslint) { | |
return configUpgrader.upgrade(originalConfig); | ||
}; | ||
|
||
eslint.docs = docs; | ||
|
||
return eslint; | ||
return require('eslint'); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const expect = require("chai").expect; | ||
const sinon = require("sinon"); | ||
|
||
const Plugins = require("eslint/lib/config/plugins"); | ||
const ModuleResolver = require("eslint/lib/util/module-resolver"); | ||
const eslintPatch = require("../lib/eslint-patch"); | ||
|
||
describe("eslint-patch", function() { | ||
let loadAll; | ||
|
||
before(function() { | ||
loadAll = Plugins.loadAll; | ||
}); | ||
|
||
after(function() { | ||
Plugins.loadAll = loadAll; | ||
}); | ||
|
||
it("intercepts plugins", function() { | ||
eslintPatch(); | ||
expect(loadAll).to.not.equal(Plugins.loadAll, "Plugins.loadAll is not patched"); | ||
}); | ||
|
||
describe("Plugins.loadAll", function() { | ||
before(function() { | ||
eslintPatch(); | ||
}); | ||
|
||
it("delegates each plugin to be loaded", function () { | ||
Plugins.getAll = sinon.stub().returns([]); | ||
Plugins.load = sinon.spy(); | ||
|
||
Plugins.loadAll([ "jasmine", "mocha" ]); | ||
|
||
expect(Plugins.load.calledWith("jasmine")).to.be.true; | ||
expect(Plugins.load.calledWith("mocha")).to.be.true; | ||
}); | ||
|
||
it("only load plugins once", function () { | ||
Plugins.getAll = sinon.stub().returns([ "node" ]); | ||
Plugins.load = sinon.spy(); | ||
|
||
Plugins.loadAll([ "node" ]); | ||
|
||
expect(Plugins.load.called).to.be.false; | ||
}); | ||
|
||
it("does not raise exception for unsupported plugins", function() { | ||
Plugins.getAll = sinon.stub().returns([]); | ||
Plugins.load = sinon.stub().throws(); | ||
|
||
function loadPlugin() { | ||
Plugins.loadAll([ "unsupported-plugin" ]); | ||
} | ||
|
||
expect(loadPlugin).to.not.throw(); | ||
}); | ||
}); | ||
|
||
describe("loading extends configuration", function() { | ||
it("patches module resolver", function() { | ||
const resolve = ModuleResolver.prototype.resolve; | ||
|
||
eslintPatch(); | ||
expect(ModuleResolver.prototype.resolve).to.not.eql(resolve); | ||
}); | ||
|
||
it("returns fake config for skipped modules", function() { | ||
eslintPatch(); | ||
Plugins.loadAll(['invalidplugin']); | ||
expect(new ModuleResolver().resolve('eslint-plugin-invalidplugin')).to.match(/.+empty-plugin.js/); | ||
}); | ||
|
||
it("does not warn user repeatedly about not supported modules", function() { | ||
console.error = sinon.spy(); | ||
eslintPatch(); | ||
|
||
for(var i=0; i<3; i++) { | ||
new ModuleResolver().resolve('eslint-plugin-bogus'); | ||
} | ||
|
||
expect(console.error.callCount).to.eql(1); | ||
}); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gordondiggs @maxjacobson I felt this was misplaced and was impacting the way we load/patch eslint, so I decoupled it from
eslint
instance. Haven't found any other use ofeslint.docs
so I think we are good, but wanted to hight light this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. We use the docs for the issue contents - as long as those still work we're probably ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed docs are still showing up correctly