Skip to content

Commit d44b762

Browse files
committedSep 11, 2015
Merge pull request #41 from joeybaker/add-linter
Add eslint
2 parents 880fd8c + 4f6404f commit d44b762

File tree

7 files changed

+264
-20
lines changed

7 files changed

+264
-20
lines changed
 

‎.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

‎.eslintrc

+238
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
{
2+
"ecmaFeatures": {
3+
},
4+
"env": {
5+
"node": true
6+
},
7+
"rules": {
8+
"comma-dangle": [2, "never"],
9+
"no-cond-assign": 2,
10+
"no-constant-condition": 2,
11+
"no-control-regex": 2,
12+
"no-debugger": 2,
13+
"no-dupe-keys": 2,
14+
"no-empty": 2,
15+
"no-empty-character-class": 2,
16+
"no-ex-assign": 2,
17+
"no-extra-boolean-cast": 2,
18+
"no-extra-parens": 0,
19+
"no-extra-semi": 2,
20+
"no-func-assign": 2,
21+
"no-inner-declarations": 2,
22+
"no-invalid-regexp": 2,
23+
"no-irregular-whitespace": 2,
24+
"no-negated-in-lhs": 2,
25+
"no-obj-calls": 2,
26+
"no-regex-spaces": 2,
27+
"quote-props": [1, "consistent-as-needed"],
28+
"no-sparse-arrays": 2,
29+
"no-unreachable": 2,
30+
"use-isnan": 2,
31+
"valid-typeof": 2,
32+
"block-scoped-var": 0,
33+
"consistent-return": 2,
34+
"curly": [
35+
1,
36+
"multi-line"
37+
],
38+
"default-case": 2,
39+
"dot-notation": 2,
40+
"eqeqeq": 2,
41+
"guard-for-in": 2,
42+
"no-alert": 1,
43+
"no-caller": 2,
44+
"no-div-regex": 2,
45+
"no-eq-null": 2,
46+
"no-eval": 2,
47+
"no-extend-native": 2,
48+
"no-extra-bind": 2,
49+
"no-fallthrough": 2,
50+
"no-floating-decimal": 2,
51+
"no-implied-eval": 2,
52+
"no-iterator": 2,
53+
"no-labels": 2,
54+
"no-lone-blocks": 2,
55+
"no-loop-func": 2,
56+
"no-multi-spaces": 1,
57+
"no-multi-str": 2,
58+
"no-native-reassign": 2,
59+
"no-new": 2,
60+
"no-new-func": 2,
61+
"no-new-wrappers": 2,
62+
"no-octal": 2,
63+
"no-octal-escape": 2,
64+
"no-proto": 2,
65+
"no-redeclare": 2,
66+
"no-return-assign": [2, "except-parens"],
67+
"no-script-url": 2,
68+
"no-self-compare": 2,
69+
"no-sequences": 2,
70+
"no-throw-literal": 2,
71+
"no-unused-expressions": 0,
72+
"no-with": 2,
73+
"radix": 2,
74+
"vars-on-top": 0,
75+
"wrap-iife": 2,
76+
"yoda": [
77+
1,
78+
"never"
79+
],
80+
"strict": [
81+
0,
82+
"never"
83+
],
84+
"no-delete-var": 2,
85+
"no-label-var": 2,
86+
"no-shadow": 2,
87+
"no-shadow-restricted-names": 2,
88+
"no-undef": 2,
89+
"no-undef-init": 2,
90+
"no-undefined": 2,
91+
"no-unused-vars": [
92+
2,
93+
"all"
94+
],
95+
"no-use-before-define": 2,
96+
"handle-callback-err": 2,
97+
"no-mixed-requires": 0,
98+
"no-new-require": 2,
99+
"no-path-concat": 2,
100+
"indent": [
101+
1,
102+
2,
103+
{"SwitchCase": 1}
104+
],
105+
"brace-style": [
106+
1,
107+
"stroustrup",
108+
{
109+
"allowSingleLine": true
110+
}
111+
],
112+
"comma-spacing": [
113+
1,
114+
{
115+
"before": false,
116+
"after": true
117+
}
118+
],
119+
"comma-style": [
120+
2,
121+
"first"
122+
],
123+
"consistent-this": [
124+
1,
125+
"self"
126+
],
127+
"eol-last": 2,
128+
"func-names": 0,
129+
"key-spacing": [
130+
1,
131+
{
132+
"beforeColon": false,
133+
"afterColon": true
134+
}
135+
],
136+
"max-nested-callbacks": [
137+
2,
138+
3
139+
],
140+
"new-cap": 2,
141+
"new-parens": 2,
142+
"no-array-constructor": 0,
143+
"no-inline-comments": 1,
144+
"no-lonely-if": 0,
145+
"no-mixed-spaces-and-tabs": 2,
146+
"no-multiple-empty-lines": 2,
147+
"no-nested-ternary": 0,
148+
"no-new-object": 2,
149+
"semi-spacing": [2, {"before": false, "after": true}],
150+
"no-spaced-func": 1,
151+
"no-ternary": 0,
152+
"no-trailing-spaces": 2,
153+
"no-underscore-dangle": 0,
154+
"one-var": [
155+
1,
156+
{
157+
"var": "never",
158+
"let": "never",
159+
"const": "never"
160+
}
161+
],
162+
"operator-assignment": [
163+
2,
164+
"always"
165+
],
166+
"padded-blocks": [
167+
1,
168+
"never"
169+
],
170+
"quote-props": [
171+
1,
172+
"as-needed"
173+
],
174+
"quotes": [
175+
2,
176+
"single"
177+
],
178+
"semi": [
179+
2,
180+
"always"
181+
],
182+
"sort-vars": 0,
183+
"space-after-keywords": [
184+
1,
185+
"always"
186+
],
187+
"space-before-blocks": 0,
188+
"space-before-function-paren": [
189+
1,
190+
"always"
191+
],
192+
"object-curly-spacing": [
193+
1,
194+
"never"
195+
],
196+
"array-bracket-spacing": [
197+
1,
198+
"never"
199+
],
200+
"space-in-parens": [
201+
1,
202+
"never"
203+
],
204+
"space-infix-ops": 2,
205+
"space-return-throw-case": 2,
206+
"space-unary-ops": [
207+
1,
208+
{
209+
"words": true,
210+
"nonwords": false
211+
}
212+
],
213+
"spaced-comment": [
214+
1,
215+
"always",
216+
{
217+
"exceptions": [
218+
"-"
219+
]
220+
}
221+
],
222+
"array-bracket-spacing": [1, "never"],
223+
"wrap-regex": 0,
224+
"constructor-super": 2,
225+
"no-this-before-super": 2,
226+
"require-yield": 2,
227+
"prefer-spread": 1,
228+
"no-useless-call": 1,
229+
"no-invalid-this": 0,
230+
"no-implicit-coercion": 0,
231+
"no-const-assign": 2,
232+
"no-class-assign": 2,
233+
"init-declarations": 0,
234+
"callback-return": [0, ["callback", "cb", "done", "next"]],
235+
"arrow-spacing": [1, {"before": true, "after": true}],
236+
"arrow-parens": 1
237+
}
238+
}

‎index.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ var stringHash = require('string-hash');
1212
*/
1313
function createScopedNameFunc (plugin) {
1414
var orig = plugin.generateScopedName;
15-
return function (name, path, css) {
15+
return function (name, filename, css) {
1616
var hash = stringHash(css).toString(36).substr(0, 5);
1717
return orig.apply(plugin, arguments) + '___' + hash;
18-
}
19-
};
18+
};
19+
}
2020

2121
/*
2222
@@ -72,9 +72,10 @@ module.exports = function (browserify, options) {
7272
var plugins = options.use || options.u;
7373
if (!plugins) {
7474
plugins = Core.defaultPlugins;
75-
} else {
75+
}
76+
else {
7677
if (typeof plugins === 'string') {
77-
plugins = [ plugins ];
78+
plugins = [plugins];
7879
}
7980
}
8081

@@ -100,7 +101,8 @@ module.exports = function (browserify, options) {
100101

101102
if (name in options) {
102103
plugin = plugin(options[name]);
103-
} else {
104+
}
105+
else {
104106
plugin = plugin.postcss || plugin();
105107
}
106108

@@ -124,7 +126,7 @@ module.exports = function (browserify, options) {
124126
loader.tokensByFile = tokensByFile;
125127

126128
loader.fetch(path.relative(rootDir, filename), '/').then(function (tokens) {
127-
var output = "module.exports = " + JSON.stringify(tokens);
129+
var output = 'module.exports = ' + JSON.stringify(tokens);
128130

129131
assign(tokensByFile, loader.tokensByFile);
130132

@@ -143,13 +145,12 @@ module.exports = function (browserify, options) {
143145
global: true
144146
});
145147

146-
browserify.on('bundle', function(bundle) {
147-
bundle.on('end', function() {
148+
browserify.on('bundle', function (bundle) {
149+
bundle.on('end', function () {
148150
// Combine the collected sources into a single CSS file
149-
var css = Object.keys(sourceByFile).map(function(file) {
151+
var css = Object.keys(sourceByFile).map(function (file) {
150152
return sourceByFile[file];
151153
}).join('\n');
152-
var args = arguments;
153154

154155
fs.writeFile(cssOutFilename, css, function (err) {
155156
if (err) {

‎package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
},
1212
"devDependencies": {
1313
"browserify": "^11.0.1",
14+
"eslint": "^1.4.0",
1415
"proxyquire": "^1.6.0",
1516
"rebundler": "^0.2.0",
1617
"tape": "^4.0.1"
1718
},
1819
"scripts": {
19-
"test": "tape tests/*.js"
20+
"test": "tape tests/*.js",
21+
"lint": "eslint index.js tests/"
2022
},
2123
"author": "joshwnj",
2224
"license": "MIT",
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
var styles = require('./styles.css');
2+
module.exports = styles;
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
var styles = require('cool-styles/styles.css');
2+
module.exports = styles;

‎tests/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ var path = require('path');
88
var casesDir = path.join(__dirname, 'cases');
99
var cssOutFilename = 'out.css';
1010

11-
// test cases are expected to have:
12-
// - main.js (entry point)
13-
// - expected.css (what to expect from css-modulesify output)
14-
fs.readdirSync(path.join(__dirname, 'cases')).forEach(runTestCase);
15-
1611
function runTestCase (dir) {
1712
tape('case: ' + dir, function (t) {
1813
var fakeFs = {
@@ -32,11 +27,11 @@ function runTestCase (dir) {
3227
var b = browserify();
3328
b.add(path.join(casesDir, dir, 'main.js'));
3429
b.plugin(cssModulesify, {
35-
rootDir: path.join(casesDir, dir),
36-
output: cssOutFilename
30+
rootDir: path.join(casesDir, dir)
31+
, output: cssOutFilename
3732
});
3833

39-
b.bundle(function (err, buf) {
34+
b.bundle(function (err) {
4035
if (err) {
4136
console.error(err);
4237
return t.fail('Unexpected error');
@@ -46,3 +41,8 @@ function runTestCase (dir) {
4641
});
4742
});
4843
}
44+
45+
// test cases are expected to have:
46+
// - main.js (entry point)
47+
// - expected.css (what to expect from css-modulesify output)
48+
fs.readdirSync(path.join(__dirname, 'cases')).forEach(runTestCase);

0 commit comments

Comments
 (0)
Please sign in to comment.