diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.eslintrc b/.eslintrc new file mode 100755 index 0000000..71199da --- /dev/null +++ b/.eslintrc @@ -0,0 +1,238 @@ +{ + "ecmaFeatures": { + }, + "env": { + "node": true + }, + "rules": { + "comma-dangle": [2, "never"], + "no-cond-assign": 2, + "no-constant-condition": 2, + "no-control-regex": 2, + "no-debugger": 2, + "no-dupe-keys": 2, + "no-empty": 2, + "no-empty-character-class": 2, + "no-ex-assign": 2, + "no-extra-boolean-cast": 2, + "no-extra-parens": 0, + "no-extra-semi": 2, + "no-func-assign": 2, + "no-inner-declarations": 2, + "no-invalid-regexp": 2, + "no-irregular-whitespace": 2, + "no-negated-in-lhs": 2, + "no-obj-calls": 2, + "no-regex-spaces": 2, + "quote-props": [1, "consistent-as-needed"], + "no-sparse-arrays": 2, + "no-unreachable": 2, + "use-isnan": 2, + "valid-typeof": 2, + "block-scoped-var": 0, + "consistent-return": 2, + "curly": [ + 1, + "multi-line" + ], + "default-case": 2, + "dot-notation": 2, + "eqeqeq": 2, + "guard-for-in": 2, + "no-alert": 1, + "no-caller": 2, + "no-div-regex": 2, + "no-eq-null": 2, + "no-eval": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-fallthrough": 2, + "no-floating-decimal": 2, + "no-implied-eval": 2, + "no-iterator": 2, + "no-labels": 2, + "no-lone-blocks": 2, + "no-loop-func": 2, + "no-multi-spaces": 1, + "no-multi-str": 2, + "no-native-reassign": 2, + "no-new": 2, + "no-new-func": 2, + "no-new-wrappers": 2, + "no-octal": 2, + "no-octal-escape": 2, + "no-proto": 2, + "no-redeclare": 2, + "no-return-assign": [2, "except-parens"], + "no-script-url": 2, + "no-self-compare": 2, + "no-sequences": 2, + "no-throw-literal": 2, + "no-unused-expressions": 0, + "no-with": 2, + "radix": 2, + "vars-on-top": 0, + "wrap-iife": 2, + "yoda": [ + 1, + "never" + ], + "strict": [ + 0, + "never" + ], + "no-delete-var": 2, + "no-label-var": 2, + "no-shadow": 2, + "no-shadow-restricted-names": 2, + "no-undef": 2, + "no-undef-init": 2, + "no-undefined": 2, + "no-unused-vars": [ + 2, + "all" + ], + "no-use-before-define": 2, + "handle-callback-err": 2, + "no-mixed-requires": 0, + "no-new-require": 2, + "no-path-concat": 2, + "indent": [ + 1, + 2, + {"SwitchCase": 1} + ], + "brace-style": [ + 1, + "stroustrup", + { + "allowSingleLine": true + } + ], + "comma-spacing": [ + 1, + { + "before": false, + "after": true + } + ], + "comma-style": [ + 2, + "first" + ], + "consistent-this": [ + 1, + "self" + ], + "eol-last": 2, + "func-names": 0, + "key-spacing": [ + 1, + { + "beforeColon": false, + "afterColon": true + } + ], + "max-nested-callbacks": [ + 2, + 3 + ], + "new-cap": 2, + "new-parens": 2, + "no-array-constructor": 0, + "no-inline-comments": 1, + "no-lonely-if": 0, + "no-mixed-spaces-and-tabs": 2, + "no-multiple-empty-lines": 2, + "no-nested-ternary": 0, + "no-new-object": 2, + "semi-spacing": [2, {"before": false, "after": true}], + "no-spaced-func": 1, + "no-ternary": 0, + "no-trailing-spaces": 2, + "no-underscore-dangle": 0, + "one-var": [ + 1, + { + "var": "never", + "let": "never", + "const": "never" + } + ], + "operator-assignment": [ + 2, + "always" + ], + "padded-blocks": [ + 1, + "never" + ], + "quote-props": [ + 1, + "as-needed" + ], + "quotes": [ + 2, + "single" + ], + "semi": [ + 2, + "always" + ], + "sort-vars": 0, + "space-after-keywords": [ + 1, + "always" + ], + "space-before-blocks": 0, + "space-before-function-paren": [ + 1, + "always" + ], + "object-curly-spacing": [ + 1, + "never" + ], + "array-bracket-spacing": [ + 1, + "never" + ], + "space-in-parens": [ + 1, + "never" + ], + "space-infix-ops": 2, + "space-return-throw-case": 2, + "space-unary-ops": [ + 1, + { + "words": true, + "nonwords": false + } + ], + "spaced-comment": [ + 1, + "always", + { + "exceptions": [ + "-" + ] + } + ], + "array-bracket-spacing": [1, "never"], + "wrap-regex": 0, + "constructor-super": 2, + "no-this-before-super": 2, + "require-yield": 2, + "prefer-spread": 1, + "no-useless-call": 1, + "no-invalid-this": 0, + "no-implicit-coercion": 0, + "no-const-assign": 2, + "no-class-assign": 2, + "init-declarations": 0, + "callback-return": [0, ["callback", "cb", "done", "next"]], + "arrow-spacing": [1, {"before": true, "after": true}], + "arrow-parens": 1 + } +} diff --git a/index.js b/index.js index 9b6195d..b4a8fb5 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,11 @@ var stringHash = require('string-hash'); */ function createScopedNameFunc (plugin) { var orig = plugin.generateScopedName; - return function (name, path, css) { + return function (name, filename, css) { var hash = stringHash(css).toString(36).substr(0, 5); return orig.apply(plugin, arguments) + '___' + hash; - } -}; + }; +} /* @@ -56,9 +56,10 @@ module.exports = function (browserify, options) { var plugins = options.use || options.u; if (!plugins) { plugins = Core.defaultPlugins; - } else { + } + else { if (typeof plugins === 'string') { - plugins = [ plugins ]; + plugins = [plugins]; } } @@ -84,7 +85,8 @@ module.exports = function (browserify, options) { if (name in options) { plugin = plugin(options[name]); - } else { + } + else { plugin = plugin.postcss || plugin(); } @@ -119,7 +121,7 @@ module.exports = function (browserify, options) { loader.tokensByFile = tokensByFile; loader.fetch(path.relative(rootDir, filename), '/').then(function (tokens) { - var output = "module.exports = " + JSON.stringify(tokens); + var output = 'module.exports = ' + JSON.stringify(tokens); assign(tokensByFile, loader.tokensByFile); @@ -138,13 +140,12 @@ module.exports = function (browserify, options) { global: true }); - browserify.on('bundle', function(bundle) { - bundle.on('end', function() { + browserify.on('bundle', function (bundle) { + bundle.on('end', function () { // Combine the collected sources into a single CSS file - var css = Object.keys(sourceByFile).map(function(file) { + var css = Object.keys(sourceByFile).map(function (file) { return sourceByFile[file]; }).join('\n'); - var args = arguments; fs.writeFile(cssOutFilename, css, function (err) { if (err) { diff --git a/package.json b/package.json index 0e57907..75f4836 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,13 @@ }, "devDependencies": { "browserify": "^11.0.1", + "eslint": "^1.4.0", "proxyquire": "^1.6.0", "tape": "^4.0.1" }, "scripts": { - "test": "tape tests/*.js" + "test": "tape tests/*.js", + "lint": "eslint index.js tests/" }, "author": "joshwnj", "license": "MIT", diff --git a/tests/cases/compose-node-module/main.js b/tests/cases/compose-node-module/main.js index 791235e..922a6aa 100644 --- a/tests/cases/compose-node-module/main.js +++ b/tests/cases/compose-node-module/main.js @@ -1 +1,2 @@ var styles = require('./styles.css'); +module.exports = styles; diff --git a/tests/cases/import-node-module/main.js b/tests/cases/import-node-module/main.js index 59f8d0d..729af44 100644 --- a/tests/cases/import-node-module/main.js +++ b/tests/cases/import-node-module/main.js @@ -1 +1,2 @@ var styles = require('cool-styles/styles.css'); +module.exports = styles; diff --git a/tests/index.js b/tests/index.js index 92e028d..f69e93d 100644 --- a/tests/index.js +++ b/tests/index.js @@ -8,11 +8,6 @@ var path = require('path'); var casesDir = path.join(__dirname, 'cases'); var cssOutFilename = 'out.css'; -// test cases are expected to have: -// - main.js (entry point) -// - expected.css (what to expect from css-modulesify output) -fs.readdirSync(path.join(__dirname, 'cases')).forEach(runTestCase); - function runTestCase (dir) { tape('case: ' + dir, function (t) { var fakeFs = { @@ -32,11 +27,11 @@ function runTestCase (dir) { var b = browserify(); b.add(path.join(casesDir, dir, 'main.js')); b.plugin(cssModulesify, { - rootDir: path.join(casesDir, dir), - output: cssOutFilename + rootDir: path.join(casesDir, dir) + , output: cssOutFilename }); - b.bundle(function (err, buf) { + b.bundle(function (err) { if (err) { console.error(err); return t.fail('Unexpected error'); @@ -46,3 +41,8 @@ function runTestCase (dir) { }); }); } + +// test cases are expected to have: +// - main.js (entry point) +// - expected.css (what to expect from css-modulesify output) +fs.readdirSync(path.join(__dirname, 'cases')).forEach(runTestCase);