Skip to content

Commit dfac79c

Browse files
committed
Custom Lint Rule no-css-modules
Value Guard Add Rules Dir
1 parent e395498 commit dfac79c

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

config/eslint.js

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module.exports = {
6969
'no-cond-assign': [WARNING, 'always'],
7070
'no-const-assign': WARNING,
7171
'no-control-regex': WARNING,
72+
'no-css-modules': WARNING,
7273
'no-delete-var': WARNING,
7374
'no-dupe-args': WARNING,
7475
'no-dupe-class-members': WARNING,

config/rules/no-css-modules.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = {
11+
create: function (context) {
12+
return {
13+
ImportDeclaration: function(node) {
14+
if (node) {
15+
var specifiers = node.specifiers || [];
16+
var value = node.source && node.source.value;
17+
18+
if (value && value.indexOf('.css') !== -1 && specifiers.length) {
19+
for (var i = 0; i < specifiers.length; i++) {
20+
var specifier = specifiers[i];
21+
22+
context.report(specifier, 'CSS modules import is restricted. ' +
23+
'Please remove the \'{{importName}}\' portion of the import.', {
24+
importName: specifier.imported ? specifier.imported.name : specifier.local.name
25+
});
26+
}
27+
}
28+
}
29+
}
30+
};
31+
}
32+
};

config/webpack.config.dev.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ module.exports = {
8686
},
8787
eslint: {
8888
configFile: path.join(__dirname, 'eslint.js'),
89-
useEslintrc: false
89+
useEslintrc: false,
90+
rulesdir: 'config/rules'
9091
},
9192
postcss: function() {
9293
return [autoprefixer];

config/webpack.config.prod.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ module.exports = {
8787
// TODO: consider separate config for production,
8888
// e.g. to enable no-console and no-debugger only in prod.
8989
configFile: path.join(__dirname, 'eslint.js'),
90-
useEslintrc: false
90+
useEslintrc: false,
91+
rulesdir: 'config/rules'
9192
},
9293
postcss: function() {
9394
return [autoprefixer];

tasks/e2e.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ npm install
3131
scripts_path=$PWD/`npm pack`
3232

3333
# lint
34-
./node_modules/.bin/eslint --ignore-path .gitignore ./
34+
./node_modules/.bin/eslint --rulesdir config/rules --ignore-path .gitignore ./
3535

3636
# Test local start command
3737
npm start -- --smoke-test

0 commit comments

Comments
 (0)