Skip to content

Commit 38e2498

Browse files
Quick and dirty - does not error with not supported plugin
Related #192
1 parent 520225e commit 38e2498

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

lib/eslint-patch.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
'use strict';
2-
var meld = require('meld');
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
var Plugins = require("eslint/lib/config/plugins");
6+
37
var docs = require('./docs');
48
var Config = require("eslint/lib/config");
59
var ConfigUpgrader = require('./config_upgrader');
610

7-
var supportedPlugins = ['react', 'babel'];
811

9-
module.exports = function patcher(eslint) {
12+
module.exports = function patcher(engine) {
1013

11-
meld.around(eslint.CLIEngine, 'loadPlugins', function(joinPoint) {
12-
var pluginNames = joinPoint.args[0];
13-
var filteredPluginNames = pluginNames.filter(function(pluginName) {
14-
return supportedPlugins.indexOf(pluginName) >= 0;
15-
});
16-
return joinPoint.proceed(filteredPluginNames);
17-
});
14+
Plugins.loadAll = function(pluginNames) {
15+
for(var index in pluginNames) {
16+
var name = pluginNames[index];
1817

19-
meld.around(eslint.CLIEngine, 'addPlugin', function() {
20-
return;
21-
});
18+
try {
19+
Plugins.load(name);
20+
console.error('>>>> Plugin loaded', name);
21+
} catch(e) {
22+
console.error('>>>> Problem loading plugin', name);
23+
}
24+
}
25+
26+
}
2227

23-
// meld.around(eslint.CLIEngine.Config, 'loadPackage', function(joinPoint) {
24-
// var filePath = joinPoint.args[0];
25-
// if (filePath.match(/^eslint-config-airbnb.*/)) {
26-
// return joinPoint.proceed();
27-
// } else {
28-
// return {};
29-
// }
30-
// });
3128

3229
const originalGetConfig = Config.prototype.getConfig;
3330
Config.prototype.getConfig = function(filePath) {
@@ -37,7 +34,8 @@ module.exports = function patcher(eslint) {
3734
return configUpgrader.upgrade(originalConfig);
3835
};
3936

40-
eslint.docs = docs;
37+
engine.docs = docs;
38+
4139

42-
return eslint;
40+
return engine;
4341
};

test/eslint-patch_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var eslint = require("eslint");
2+
var expect = require("chai").expect;
3+
4+
describe('eslint-patch', function() {
5+
it('intercept plugins', function() {
6+
var Plugins = require('eslint/lib/config/plugins');
7+
var loadAll = Plugins.loadAll;
8+
9+
var patch = require("../lib/eslint-patch");
10+
patch(eslint);
11+
12+
expect(loadAll).to.not.equal(Plugins.loadAll, 'Plugins.loadAll is not patched');
13+
});
14+
});

0 commit comments

Comments
 (0)