Skip to content

Commit

Permalink
add strict css module checks to avoid leakage (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-gadd authored Mar 21, 2019
1 parent 16237e5 commit 687a8ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
"slash": "1.0.0",
"source-map-loader-cli": "0.0.1",
"strip-ansi": "3.0.1",
"stylelint": "9.10.1",
"stylelint-webpack-plugin": "0.10.5",
"terser-webpack-plugin": "1.1.0",
"ts-loader": "5.3.0",
"ts-node": "7.0.1",
Expand Down
26 changes: 26 additions & 0 deletions src/base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const WrapperPlugin = require('wrapper-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');

const stylelint = require('stylelint');
const StyleLintPlugin = require('stylelint-webpack-plugin');

const basePath = process.cwd();
const srcPath = path.join(basePath, 'src');
const testPath = path.join(basePath, 'tests');
Expand Down Expand Up @@ -344,6 +347,29 @@ export default function webpackConfigFactory(args: any): webpack.Configuration {
devtool: 'source-map',
watchOptions: { ignored: /node_modules/ },
plugins: removeEmpty([
new StyleLintPlugin({
config: {
rules: {
'selector-max-type': [0, { ignoreTypes: '.' }],
'selector-max-universal': [0]
}
},
emitErrors: false,
formatter: (results: any) => {
return stylelint.formatters
.string(results)
.replace(/selector-max-type|selector-max-universal/g, 'css-modules')
.replace(
/to have no more than (\d*) type selectors/g,
'to not contain element selectors due to unsafe isolation'
)
.replace(
/to have no more than (\d*) universal selectors/g,
'to not contain universal (*) selectors due to unsafe isolation'
);
},
files: ['**/*.m.css']
}),
singleBundle &&
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
Expand Down

0 comments on commit 687a8ed

Please sign in to comment.