Skip to content

Commit c44c1e4

Browse files
committed
Add automatic linting check
This uses prettier and all of the opinionated defaults from prettier. I'm not always a fan of some of the decisions, but it allows us to not think about code style. This enables CircleCI checks on branches and pull requests. It's also usable locally. Also drop fomantic-ui dependency to avoid building sui and pin node for CircleCI
1 parent adfd815 commit c44c1e4

File tree

7 files changed

+117
-14
lines changed

7 files changed

+117
-14
lines changed

.circleci/config.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: 2.1
2+
3+
commands:
4+
run-lint:
5+
description: "Run code linter"
6+
steps:
7+
- checkout
8+
- run: npm ci
9+
- run: npm run lint
10+
run-build:
11+
description: "Ensure built assets are up to date"
12+
steps:
13+
- checkout
14+
- run: npm ci
15+
- run: npm run build
16+
- run:
17+
name: Ensure built assets are up to date
18+
command: |
19+
if [[ `git status dist/ --porcelain` ]]
20+
then
21+
echo "ERROR: assets are out of date. Make sure to run 'npm run build' on your branch."
22+
git status dist/ --porcelain
23+
exit 1
24+
fi
25+
26+
jobs:
27+
lint:
28+
docker:
29+
- image: 'cimg/node:14.18'
30+
steps:
31+
- run-lint: {}
32+
build:
33+
docker:
34+
- image: 'cimg/node:14.18'
35+
steps:
36+
- run-build: {}
37+
38+
workflows:
39+
version: 2
40+
tests:
41+
jobs:
42+
- lint
43+
- build

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
node_modules/
22
.node-version
3-
4-
semantic/
5-
semantic.json

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dist/
2+
examples/
3+
*.rst
4+
*.eot
5+
*.woff
6+
*.woff2
7+
*.ttf
8+
*.svg

README.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You should be able to execute the various npm commands below at this point.
4949
Running the development server
5050
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5151

52-
You can run the development server with::
52+
You can run the development server with:
5353

5454
.. code:: console
5555
@@ -61,6 +61,25 @@ http://localhost:8080/
6161
You can view some of the test HTML on the development server as well, for
6262
example http://localhost:8080/examples/theme/
6363

64+
Running linting and formatting
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66+
67+
Similar to other front end projects, and our Python code, we use automatic
68+
linting and formatting for styling code to a unified format. For CSS/JS, we use
69+
``prettier``, which is opinionated but mostly makes good code style choices.
70+
71+
To run linting checks, which will only report errors:
72+
73+
.. code:: console
74+
75+
$ npm run lint
76+
77+
To automatically format code:
78+
79+
.. code:: console
80+
81+
$ npm run format
82+
6483
Build production assets
6584
~~~~~~~~~~~~~~~~~~~~~~~
6685

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"clean": "rm -rfv dist/*; exit 0",
88
"build": "npm run clean && webpack --mode=production --progress --colors",
99
"dev": "webpack-dev-server --mode=development",
10-
"lint": "prettier -c src/",
11-
"format": "prettier --write src/",
10+
"lint": "prettier --check 'src/**' '*.js' '*.json'",
11+
"format": "prettier --write 'src/**' '*.js' '*.json'",
1212
"test": "jest src/js/tests/"
1313
},
1414
"repository": {
@@ -25,7 +25,9 @@
2525
"node": "<15.0.0",
2626
"npm": "<7.0.0"
2727
},
28-
"dependencies": {},
28+
"dependencies": {
29+
"prettier": "^2.5.0"
30+
},
2931
"devDependencies": {
3032
"@babel/core": "^7.16.0",
3133
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
@@ -34,7 +36,6 @@
3436
"create-fomantic-icons": "^1.0.4",
3537
"css-loader": "^3.1.0",
3638
"file-loader": "^3.0.1",
37-
"fomantic-ui": "^2.8.8",
3839
"fomantic-ui-less": "^2.8.8",
3940
"imports-loader": "^0.8.0",
4041
"jest": "^26.4.2",
@@ -45,7 +46,6 @@
4546
"matchdep": "~1.0.1",
4647
"mini-css-extract-plugin": "^0.6.0",
4748
"optimize-css-assets-webpack-plugin": "^5.0.3",
48-
"prettier": "^2.0.5",
4949
"resolve-url-loader": "^2.2.1",
5050
"sanitize-html": "^1.23.0",
5151
"style-loader": "^0.23.1",
@@ -70,5 +70,19 @@
7070
"globals": {
7171
"__webpack_public_path__": null
7272
}
73+
},
74+
"prettier": {
75+
"overrides": [
76+
{
77+
"files": [
78+
"src/**/*.overrides",
79+
"src/**/*.variables",
80+
"src/sui/theme.config"
81+
],
82+
"options": {
83+
"parser": "less"
84+
}
85+
}
86+
]
7387
}
7488
}

src/js/site.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
import "fomantic-ui";
1+
import "fomantic-ui-less/definitions/modules/nag";
2+
import "fomantic-ui-less/definitions/modules/tab";
3+
import "fomantic-ui-less/definitions/modules/transition";
4+
import "fomantic-ui-less/definitions/modules/rating";
5+
import "fomantic-ui-less/definitions/modules/modal";
6+
import "fomantic-ui-less/definitions/modules/search";
7+
import "fomantic-ui-less/definitions/modules/sticky";
8+
import "fomantic-ui-less/definitions/modules/shape";
9+
import "fomantic-ui-less/definitions/modules/accordion";
10+
import "fomantic-ui-less/definitions/modules/dropdown";
11+
import "fomantic-ui-less/definitions/modules/sidebar";
12+
import "fomantic-ui-less/definitions/modules/dimmer";
13+
import "fomantic-ui-less/definitions/modules/checkbox";
14+
import "fomantic-ui-less/definitions/modules/slider";
15+
import "fomantic-ui-less/definitions/modules/calendar";
16+
import "fomantic-ui-less/definitions/modules/popup";
17+
import "fomantic-ui-less/definitions/modules/embed";
18+
import "fomantic-ui-less/definitions/modules/progress";
19+
import "fomantic-ui-less/definitions/modules/toast";
20+
import "fomantic-ui-less/definitions/behaviors/visibility";
21+
import "fomantic-ui-less/definitions/behaviors/form";
22+
import "fomantic-ui-less/definitions/behaviors/state";
23+
import "fomantic-ui-less/definitions/behaviors/api";
24+
import "fomantic-ui-less/definitions/globals/site";

0 commit comments

Comments
 (0)