Skip to content

Commit 7206a2a

Browse files
authored
Add pre-commit hook for linting and code autoformatting. (rjsf-team#510)
Also updated prettier options to use es5 trailing commas.
1 parent 3eb6dd8 commit 7206a2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1452
-1438
lines changed

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@
77
"build:lib": "rimraf lib && cross-env NODE_ENV=production babel -d lib/ src/",
88
"build:dist": "rimraf dist && cross-env NODE_ENV=production webpack --config webpack.config.dist.js --optimize-minimize",
99
"build:playground": "rimraf build && cross-env NODE_ENV=production webpack --config webpack.config.prod.js --optimize-minimize && cp playground/index.prod.html build/index.html",
10-
"cs-check": "prettier-check --jsx-bracket-same-line '{playground,src,test}/**/*.js'",
11-
"cs-format": "prettier --jsx-bracket-same-line '{playground,src,test}/**/*.js' --write",
10+
"cs-check": "prettier-check $npm_package_prettierOptions '{playground,src,test}/**/*.js'",
11+
"cs-format": "prettier $npm_package_prettierOptions '{playground,src,test}/**/*.js' --write",
1212
"dist": "npm run build:lib && npm run build:dist",
1313
"lint": "eslint src test playground",
14+
"precommit": "lint-staged",
1415
"publish-to-gh-pages": "npm run build:playground && gh-pages --dist build/",
1516
"publish-to-npm": "npm run build:readme && npm run dist && npm publish",
1617
"start": "node devServer.js",
1718
"tdd": "cross-env NODE_ENV=test mocha --compilers js:babel-register --watch --require ./test/setup-jsdom.js test/**/*_test.js",
1819
"test": " cross-env NODE_ENV=test mocha --compilers js:babel-register --require ./test/setup-jsdom.js test/**/*_test.js"
1920
},
21+
"prettierOptions": "--jsx-bracket-same-line --trailing-comma es5",
22+
"lint-staged": {
23+
"{playground,src,test}/**/*.js": [
24+
"npm run lint",
25+
"npm run cs-format",
26+
"git add"
27+
]
28+
},
2029
"main": "lib/index.js",
2130
"files": [
2231
"dist",
@@ -59,7 +68,9 @@
5968
"extract-text-webpack-plugin": "^1.0.1",
6069
"gh-pages": "^0.11.0",
6170
"html": "0.0.10",
71+
"husky": "^0.13.2",
6272
"jsdom": "^8.3.0",
73+
"lint-staged": "^3.3.1",
6374
"mocha": "^2.5.3",
6475
"prettier": "^0.22.0",
6576
"prettier-check": "^1.0.0",

playground/app.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,81 +48,81 @@ const cmOptions = {
4848
mode: {
4949
name: "javascript",
5050
json: true,
51-
statementIndent: 2
51+
statementIndent: 2,
5252
},
5353
lineNumbers: true,
5454
lineWrapping: true,
5555
indentWithTabs: false,
56-
tabSize: 2
56+
tabSize: 2,
5757
};
5858
const themes = {
5959
default: {
60-
stylesheet: "//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
60+
stylesheet: "//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
6161
},
6262
cerulean: {
63-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/cerulean/bootstrap.min.css"
63+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/cerulean/bootstrap.min.css",
6464
},
6565
cosmo: {
66-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/cosmo/bootstrap.min.css"
66+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/cosmo/bootstrap.min.css",
6767
},
6868
cyborg: {
6969
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/cyborg/bootstrap.min.css",
70-
editor: "blackboard"
70+
editor: "blackboard",
7171
},
7272
darkly: {
7373
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/darkly/bootstrap.min.css",
74-
editor: "mbo"
74+
editor: "mbo",
7575
},
7676
flatly: {
7777
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/flatly/bootstrap.min.css",
78-
editor: "ttcn"
78+
editor: "ttcn",
7979
},
8080
journal: {
81-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/journal/bootstrap.min.css"
81+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/journal/bootstrap.min.css",
8282
},
8383
lumen: {
84-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/lumen/bootstrap.min.css"
84+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/lumen/bootstrap.min.css",
8585
},
8686
paper: {
87-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/paper/bootstrap.min.css"
87+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/paper/bootstrap.min.css",
8888
},
8989
readable: {
90-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/readable/bootstrap.min.css"
90+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/readable/bootstrap.min.css",
9191
},
9292
sandstone: {
9393
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/sandstone/bootstrap.min.css",
94-
editor: "solarized"
94+
editor: "solarized",
9595
},
9696
simplex: {
9797
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/simplex/bootstrap.min.css",
98-
editor: "ttcn"
98+
editor: "ttcn",
9999
},
100100
slate: {
101101
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/slate/bootstrap.min.css",
102-
editor: "monokai"
102+
editor: "monokai",
103103
},
104104
spacelab: {
105-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/spacelab/bootstrap.min.css"
105+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/spacelab/bootstrap.min.css",
106106
},
107107
"solarized-dark": {
108108
stylesheet: "//cdn.rawgit.com/aalpern/bootstrap-solarized/master/bootstrap-solarized-dark.css",
109-
editor: "dracula"
109+
editor: "dracula",
110110
},
111111
"solarized-light": {
112112
stylesheet: "//cdn.rawgit.com/aalpern/bootstrap-solarized/master/bootstrap-solarized-light.css",
113-
editor: "solarized"
113+
editor: "solarized",
114114
},
115115
superhero: {
116116
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/superhero/bootstrap.min.css",
117-
editor: "dracula"
117+
editor: "dracula",
118118
},
119119
united: {
120-
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/united/bootstrap.min.css"
120+
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/united/bootstrap.min.css",
121121
},
122122
yeti: {
123123
stylesheet: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.6/yeti/bootstrap.min.css",
124-
editor: "eclipse"
125-
}
124+
editor: "eclipse",
125+
},
126126
};
127127

128128
class GeoPosition extends Component {
@@ -262,7 +262,7 @@ class Selector extends Component {
262262
function ThemeSelector({ theme, select }) {
263263
const themeSchema = {
264264
type: "string",
265-
enum: Object.keys(themes)
265+
enum: Object.keys(themes),
266266
};
267267
return (
268268
<Form
@@ -287,7 +287,7 @@ class App extends Component {
287287
validate,
288288
editor: "default",
289289
theme: "default",
290-
liveValidate: true
290+
liveValidate: true,
291291
};
292292
}
293293

@@ -335,7 +335,7 @@ class App extends Component {
335335
theme,
336336
editor,
337337
ArrayFieldTemplate,
338-
transformErrors
338+
transformErrors,
339339
} = this.state;
340340

341341
return (

playground/samples/arrays.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module.exports = {
66
properties: {
77
name: {
88
type: "string",
9-
default: "Default name"
10-
}
11-
}
12-
}
9+
default: "Default name",
10+
},
11+
},
12+
},
1313
},
1414
type: "object",
1515
properties: {
@@ -18,17 +18,17 @@ module.exports = {
1818
title: "A list of strings",
1919
items: {
2020
type: "string",
21-
default: "bazinga"
22-
}
21+
default: "bazinga",
22+
},
2323
},
2424
multipleChoicesList: {
2525
type: "array",
2626
title: "A multiple choices list",
2727
items: {
2828
type: "string",
29-
enum: ["foo", "bar", "fuzz", "qux"]
29+
enum: ["foo", "bar", "fuzz", "qux"],
3030
},
31-
uniqueItems: true
31+
uniqueItems: true,
3232
},
3333
fixedItemsList: {
3434
type: "array",
@@ -37,25 +37,25 @@ module.exports = {
3737
{
3838
title: "A string value",
3939
type: "string",
40-
default: "lorem ipsum"
40+
default: "lorem ipsum",
4141
},
4242
{
4343
title: "a boolean value",
44-
type: "boolean"
45-
}
44+
type: "boolean",
45+
},
4646
],
4747
additionalItems: {
4848
title: "Additional item",
49-
type: "number"
50-
}
49+
type: "number",
50+
},
5151
},
5252
minItemsList: {
5353
type: "array",
5454
title: "A list with a minimal number of items",
5555
minItems: 3,
5656
items: {
57-
$ref: "#/definitions/Thing"
58-
}
57+
$ref: "#/definitions/Thing",
58+
},
5959
},
6060
nestedList: {
6161
type: "array",
@@ -65,33 +65,33 @@ module.exports = {
6565
title: "Inner list",
6666
items: {
6767
type: "string",
68-
default: "lorem ipsum"
69-
}
70-
}
68+
default: "lorem ipsum",
69+
},
70+
},
7171
},
7272
unorderable: {
7373
title: "Unorderable items",
7474
type: "array",
7575
items: {
7676
type: "string",
77-
default: "lorem ipsum"
78-
}
77+
default: "lorem ipsum",
78+
},
7979
},
8080
unremovable: {
8181
title: "Unremovable items",
8282
type: "array",
8383
items: {
8484
type: "string",
85-
default: "lorem ipsum"
86-
}
85+
default: "lorem ipsum",
86+
},
8787
},
8888
noToolbar: {
8989
title: "No add, remove and order buttons",
9090
type: "array",
9191
items: {
9292
type: "string",
93-
default: "lorem ipsum"
94-
}
93+
default: "lorem ipsum",
94+
},
9595
},
9696
fixedNoToolbar: {
9797
title: "Fixed array without buttons",
@@ -100,56 +100,56 @@ module.exports = {
100100
{
101101
title: "A number",
102102
type: "number",
103-
default: 42
103+
default: 42,
104104
},
105105
{
106106
title: "A boolean",
107107
type: "boolean",
108-
default: false
109-
}
108+
default: false,
109+
},
110110
],
111111
additionalItems: {
112112
title: "A string",
113113
type: "string",
114-
default: "lorem ipsum"
115-
}
116-
}
117-
}
114+
default: "lorem ipsum",
115+
},
116+
},
117+
},
118118
},
119119
uiSchema: {
120120
multipleChoicesList: {
121-
"ui:widget": "checkboxes"
121+
"ui:widget": "checkboxes",
122122
},
123123
fixedItemsList: {
124124
items: [{ "ui:widget": "textarea" }, { "ui:widget": "select" }],
125125
additionalItems: {
126-
"ui:widget": "updown"
127-
}
126+
"ui:widget": "updown",
127+
},
128128
},
129129
unorderable: {
130130
"ui:options": {
131-
orderable: false
132-
}
131+
orderable: false,
132+
},
133133
},
134134
unremovable: {
135135
"ui:options": {
136-
removable: false
137-
}
136+
removable: false,
137+
},
138138
},
139139
noToolbar: {
140140
"ui:options": {
141141
addable: false,
142142
orderable: false,
143-
removable: false
144-
}
143+
removable: false,
144+
},
145145
},
146146
fixedNoToolbar: {
147147
"ui:options": {
148148
addable: false,
149149
orderable: false,
150-
removable: false
151-
}
152-
}
150+
removable: false,
151+
},
152+
},
153153
},
154154
formData: {
155155
listOfStrings: ["foo", "bar"],
@@ -159,6 +159,6 @@ module.exports = {
159159
unorderable: ["one", "two"],
160160
unremovable: ["one", "two"],
161161
noToolbar: ["one", "two"],
162-
fixedNoToolbar: [42, true, "additional item one", "additional item two"]
163-
}
162+
fixedNoToolbar: [42, true, "additional item one", "additional item two"],
163+
},
164164
};

playground/samples/custom.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ module.exports = {
55
required: ["lat", "lon"],
66
properties: {
77
lat: {
8-
type: "number"
8+
type: "number",
99
},
1010
lon: {
11-
type: "number"
12-
}
13-
}
11+
type: "number",
12+
},
13+
},
1414
},
1515
uiSchema: {
16-
"ui:field": "geo"
16+
"ui:field": "geo",
1717
},
1818
formData: {
1919
lat: 0,
20-
lon: 0
21-
}
20+
lon: 0,
21+
},
2222
};

0 commit comments

Comments
 (0)