1 | (function() {
|
2 | var path, resolve;
|
3 |
|
4 | path = require('path');
|
5 |
|
6 | resolve = require('resolve').sync;
|
7 |
|
8 |
|
9 | module.exports = {
|
10 | require: function(moduleName) {
|
11 | var rulePath;
|
12 | try {
|
13 |
|
14 | rulePath = resolve(moduleName, {
|
15 | basedir: process.cwd(),
|
16 | extensions: ['.js', '.coffee', '.litcoffee', '.coffee.md']
|
17 | });
|
18 | return require(rulePath);
|
19 | } catch (error) {}
|
20 | try {
|
21 |
|
22 | return require(moduleName);
|
23 | } catch (error) {}
|
24 | try {
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | return require(path.resolve(process.cwd(), moduleName));
|
32 | } catch (error) {}
|
33 |
|
34 |
|
35 |
|
36 | return require(moduleName);
|
37 | },
|
38 | loadFromConfig: function(coffeelint, config) {
|
39 | var data, results, ruleName;
|
40 | results = [];
|
41 | for (ruleName in config) {
|
42 | data = config[ruleName];
|
43 | if ((data != null ? data.module : void 0) != null) {
|
44 | results.push(this.loadRule(coffeelint, data.module, ruleName));
|
45 | }
|
46 | }
|
47 | return results;
|
48 | },
|
49 |
|
50 | loadRule: function(coffeelint, moduleName, ruleName = void 0) {
|
51 | var e, i, len, results, rule, ruleModule;
|
52 | try {
|
53 | ruleModule = this.require(moduleName);
|
54 |
|
55 | if (typeof ruleModule === 'function') {
|
56 | return coffeelint.registerRule(ruleModule, ruleName);
|
57 | } else {
|
58 | results = [];
|
59 |
|
60 | for (i = 0, len = ruleModule.length; i < len; i++) {
|
61 | rule = ruleModule[i];
|
62 | results.push(coffeelint.registerRule(rule));
|
63 | }
|
64 | return results;
|
65 | }
|
66 | } catch (error) {
|
67 | e = error;
|
68 |
|
69 | console.error(`Error loading ${moduleName}`);
|
70 | throw e;
|
71 | }
|
72 | }
|
73 | };
|
74 |
|
75 |
|
76 |
|
77 | }).call(this);
|