Skip to content

Commit

Permalink
Custom Lint Rule no-css-modules
Browse files Browse the repository at this point in the history
Value Guard

Add Rules Dir
  • Loading branch information
casesandberg committed Jul 22, 2016
1 parent e395498 commit dfac79c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = {
'no-cond-assign': [WARNING, 'always'],
'no-const-assign': WARNING,
'no-control-regex': WARNING,
'no-css-modules': WARNING,
'no-delete-var': WARNING,
'no-dupe-args': WARNING,
'no-dupe-class-members': WARNING,
Expand Down
32 changes: 32 additions & 0 deletions config/rules/no-css-modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

module.exports = {
create: function (context) {
return {
ImportDeclaration: function(node) {
if (node) {
var specifiers = node.specifiers || [];
var value = node.source && node.source.value;

if (value && value.indexOf('.css') !== -1 && specifiers.length) {
for (var i = 0; i < specifiers.length; i++) {
var specifier = specifiers[i];

context.report(specifier, 'CSS modules import is restricted. ' +
'Please remove the \'{{importName}}\' portion of the import.', {
importName: specifier.imported ? specifier.imported.name : specifier.local.name
});
}
}
}
}
};
}
};
3 changes: 2 additions & 1 deletion config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ module.exports = {
},
eslint: {
configFile: path.join(__dirname, 'eslint.js'),
useEslintrc: false
useEslintrc: false,
rulesdir: 'config/rules'
},
postcss: function() {
return [autoprefixer];
Expand Down
3 changes: 2 additions & 1 deletion config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ module.exports = {
// TODO: consider separate config for production,
// e.g. to enable no-console and no-debugger only in prod.
configFile: path.join(__dirname, 'eslint.js'),
useEslintrc: false
useEslintrc: false,
rulesdir: 'config/rules'
},
postcss: function() {
return [autoprefixer];
Expand Down
2 changes: 1 addition & 1 deletion tasks/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ npm install
scripts_path=$PWD/`npm pack`

# lint
./node_modules/.bin/eslint --ignore-path .gitignore ./
./node_modules/.bin/eslint --rulesdir config/rules --ignore-path .gitignore ./

# Test local start command
npm start -- --smoke-test
Expand Down

0 comments on commit dfac79c

Please sign in to comment.