Skip to content

Add eslint #41

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

Merged
merged 4 commits into from
Sep 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
238 changes: 238 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -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
}
}
23 changes: 12 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
};
}

/*

Expand Down Expand Up @@ -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];
}
}

Expand All @@ -84,7 +85,8 @@ module.exports = function (browserify, options) {

if (name in options) {
plugin = plugin(options[name]);
} else {
}
else {
plugin = plugin.postcss || plugin();
}

Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/cases/compose-node-module/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
var styles = require('./styles.css');
module.exports = styles;
1 change: 1 addition & 0 deletions tests/cases/import-node-module/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
var styles = require('cool-styles/styles.css');
module.exports = styles;
16 changes: 8 additions & 8 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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');
Expand All @@ -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);