Skip to content

Commit 88486be

Browse files
committed
Added react-app-rewire-styled-components
stylelint-processor-styled-components を有効にすると stylelint-config-airbnb が無効になるため、public に .stylelintrc.js を新規作成し対応。 styled-components/stylelint-processor-styled-components#187 fix オプションを有効にするとビルドでループが発生するため、package.json の resolution に stylelint-webpack-plugin を定義。 webpack-contrib/stylelint-webpack-plugin#96 stylelint-config-prettier を有効化。
1 parent 6d29b27 commit 88486be

File tree

7 files changed

+277
-21
lines changed

7 files changed

+277
-21
lines changed

.stylelintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module.exports = {
22
processors: ['stylelint-processor-styled-components'],
3-
extends: ['stylelint-config-airbnb', 'stylelint-config-styled-components'],
3+
extends: [
4+
'stylelint-config-airbnb',
5+
'stylelint-config-prettier',
6+
'stylelint-config-styled-components',
7+
],
48
};

config-overrides.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
const rewireEslint = require('react-app-rewire-eslint');
2+
const rewireStylelint = require('react-app-rewire-stylelint');
23
const rewireReactHotLoader = require('react-app-rewire-hot-loader');
34
const rewireStyledComponents = require('react-app-rewire-styled-components');
45

56
module.exports = (config, env) => {
67
let overrodeConfig = Object.assign({}, config);
7-
overrodeConfig = rewireEslint(config, env);
8+
overrodeConfig = rewireEslint(overrodeConfig, env);
9+
overrodeConfig = rewireStylelint.withLoaderOptions({
10+
files: ['public/**/*.{s?(a|c)ss,html}'],
11+
emitErrors: false,
12+
fix: true,
13+
})(overrodeConfig, env);
14+
overrodeConfig = rewireStylelint.withLoaderOptions({
15+
files: ['src/**/*.{js,jsx}'],
16+
emitErrors: false,
17+
})(overrodeConfig, env);
818
overrodeConfig = rewireReactHotLoader(overrodeConfig, env);
9-
overrodeConfig = rewireStyledComponents(config, env, {
19+
overrodeConfig = rewireStyledComponents(overrodeConfig, env, {
1020
displayName: true,
1121
});
1222
return overrodeConfig;

lint-staged.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module.exports = {
22
linters: {
33
'docs/**': ['yarn lint:text --fix', 'git add'],
4-
'**/*.js': ['yarn lint:js --fix', 'git add'],
5-
'**/*.{css,scss,html}': ['yarn lint:css --fix', 'git add'],
6-
'**/*.test.js': ['yarn coverage', 'git add'],
4+
'**/*.{js,jsx}': ['yarn lint:js --fix', 'git add'],
5+
'public/**/*.{s?(a|c)ss,html}': ['yarn lint:css --fix', 'git add'],
6+
'src/**/*.{js,jsx}': ['yarn lint:sc', 'git add'],
7+
'**/*.test.{js,jsx}': ['yarn coverage', 'git add'],
78
},
89
ignore: ['/node_modules/**', '/build/**'],
910
};

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
"test": "react-app-rewired test --env=jsdom",
1616
"coverage": "yarn test --coverage",
1717
"eject": "react-scripts eject",
18-
"lint": "yarn lint:text && yarn lint:js && yarn lint:css",
19-
"lint:fix": "concurrently 'yarn lint:text --fix' 'yarn lint:js --fix' 'yarn lint:css --fix'",
18+
"lint": "concurrently 'yarn lint:text' 'yarn lint:js' 'yarn lint:css' 'yarn lint:sc'",
19+
"lint:fix": "concurrently 'yarn lint:text --fix' 'yarn lint:js --fix' 'yarn lint:css --fix' 'yarn lint:sc'",
2020
"lint:text": "textlint 'docs/**'",
2121
"lint:js": "eslint .",
22-
"lint:css": "stylelint 'src/**/*.{css,scss}' './public/index.html'",
22+
"lint:css": "stylelint 'public/**/*.{s?(a|c)ss,html}'",
23+
"lint:sc": "stylelint 'src/**/*.{js,jsx}'",
2324
"storybook": "start-storybook -p 9009 -s public",
2425
"build-storybook": "build-storybook -s public"
2526
},
@@ -56,22 +57,26 @@
5657
"react-app-rewire-eslint": "^0.2.3",
5758
"react-app-rewire-hot-loader": "^1.0.1",
5859
"react-app-rewire-styled-components": "^3.0.2",
60+
"react-app-rewire-stylelint": "^0.1.1",
5961
"react-app-rewired": "^1.5.2",
6062
"react-test-renderer": "^16.4.1",
6163
"storybook-addon-jsx": "^5.3.0",
6264
"storybook-addon-smart-knobs": "^3.3.1",
63-
"stylelint": "^8.0.0",
65+
"stylelint": "^9.3.0",
6466
"stylelint-config-airbnb": "^0.0.0",
67+
"stylelint-config-prettier": "^3.3.0",
6568
"stylelint-config-styled-components": "^0.1.1",
6669
"stylelint-order": "^0.7.0",
6770
"stylelint-processor-styled-components": "^1.3.1",
6871
"stylelint-scss": "^1.2.1",
72+
"stylelint-webpack-plugin": "0.10.4",
6973
"textlint": "^10.2.1",
7074
"textlint-rule-preset-ja-technical-writing": "^3.0.1",
7175
"textlint-rule-prh": "^5.0.1",
7276
"textlint-rule-spellcheck-tech-word": "^5.0.0"
7377
},
7478
"resolutions": {
79+
"stylelint-webpack-plugin": "0.10.4",
7580
"eslint": "^4.19.1",
7681
"eslint-plugin-import": "^2.12.0",
7782
"eslint-plugin-jsx-a11y": "^6.0.3",

public/.stylelintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['stylelint-config-airbnb', 'stylelint-config-prettier'],
3+
};

src/App/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const AppHeader = style.header`
1515
`;
1616

1717
const spin = keyframes`
18+
1819
from {
1920
transform: rotate(0deg);
2021
}

0 commit comments

Comments
 (0)