Skip to content

Commit 14f4585

Browse files
committed
chore: add prettier
1 parent 82cfa17 commit 14f4585

File tree

7 files changed

+80
-34
lines changed

7 files changed

+80
-34
lines changed

.eslintrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
module.exports = {
2-
extends: "eslint:recommended",
2+
extends: ["eslint:recommended", "plugin:prettier/recommended"],
33
env: {
44
node: true,
55
jest: true,
66
browser: true,
77
es6: true,
88
},
9-
parser: "babel-eslint"
9+
parser: "babel-eslint",
10+
rules: {
11+
"prettier/prettier": "error",
12+
},
1013
};

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
"scripts": {
88
"build": "rollup --config",
99
"lint": "eslint src/**",
10-
"prerelease": "yarn test && yarn build && yarn size",
10+
"prerelease": "yarn prettier:check && yarn test && yarn build && yarn size",
1111
"release": "standard-version --dry-run -a",
1212
"size": "size-limit",
13+
"prettier:check": "prettier --check 'src/**/*.{js,mdx}'",
1314
"test": "jest"
1415
},
1516
"files": [
@@ -46,9 +47,12 @@
4647
"babel-preset-react": "^6.24.1",
4748
"cz-conventional-changelog": "3.2.0",
4849
"eslint": "^7.0.0",
50+
"eslint-config-prettier": "^6.11.0",
51+
"eslint-plugin-prettier": "^3.1.3",
4952
"husky": "^4.2.5",
5053
"jest": "^24.9.0",
5154
"lint-staged": "^10.2.2",
55+
"prettier": "^2.0.5",
5256
"react-test-renderer": "^16.12.0",
5357
"rollup": "^1.29.0",
5458
"rollup-plugin-babel": "^4.3.3",
@@ -81,6 +85,7 @@
8185
],
8286
"lint-staged": {
8387
"src/**/*.js": [
88+
"prettier --write",
8489
"eslint --fix",
8590
"git add"
8691
]

prettier.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
printWidth: 80,
3+
singleQuote: true,
4+
trailingComma: "all",
5+
arrowParens: "always",
6+
};

src/constants.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
const PER_FIELD_CONFIG = {
2-
defaultValue: { type: "any", optional: true },
2+
defaultValue: { type: 'any', optional: true },
33
required: [
4-
{ type: "boolean", optional: true },
4+
{ type: 'boolean', optional: true },
55
{
6-
type: "object",
6+
type: 'object',
77
optional: true,
88
props: {
9-
errorMsg: { type: "string" },
9+
errorMsg: { type: 'string' },
1010
},
1111
},
1212
],
1313
min: [
14-
{ type: "number", optional: true, positive: true, integer: true },
14+
{ type: 'number', optional: true, positive: true, integer: true },
1515
{
16-
type: "object",
16+
type: 'object',
1717
optional: true,
1818
props: {
19-
errorMsg: { type: "string" },
20-
length: { type: "number", positive: true, integer: true },
19+
errorMsg: { type: 'string' },
20+
length: { type: 'number', positive: true, integer: true },
2121
},
2222
},
2323
],
2424
max: [
25-
{ type: "number", optional: true, positive: true, integer: true },
25+
{ type: 'number', optional: true, positive: true, integer: true },
2626
{
27-
type: "object",
27+
type: 'object',
2828
optional: true,
2929
props: {
30-
errorMsg: { type: "string" },
31-
length: { type: "number", positive: true, integer: true },
30+
errorMsg: { type: 'string' },
31+
length: { type: 'number', positive: true, integer: true },
3232
},
3333
},
3434
],
3535
patterns: {
36-
type: "array",
36+
type: 'array',
3737
items: {
38-
type: "object",
38+
type: 'object',
3939
props: {
40-
regex: { type: "regex" },
41-
errorMsg: { type: "string" },
40+
regex: { type: 'regex' },
41+
errorMsg: { type: 'string' },
4242
},
4343
},
4444
optional: true,
4545
},
46-
validationFns: { type: "array", items: "function", optional: true },
47-
extraInfo: { type: "any", optional: true },
46+
validationFns: { type: 'array', items: 'function', optional: true },
47+
extraInfo: { type: 'any', optional: true },
4848
};
4949

5050
export const PER_FIELD_SCHEMA = {
@@ -55,9 +55,9 @@ export const PER_FIELD_SCHEMA = {
5555
export const FIELD_CONFIG_SCHEMA = {
5656
$$strict: true, // no additional properties allowed
5757
configs: {
58-
type: "array",
58+
type: 'array',
5959
items: {
60-
type: "object",
60+
type: 'object',
6161
props: PER_FIELD_CONFIG,
6262
},
6363
},

src/schema-validator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import Validator from "fastest-validator";
1+
import Validator from 'fastest-validator';
22

33
const validator = new Validator({
44
messages: {
55
regex: "The '{field}' field must be an valid regex! Actual: {actual}",
66
},
77
});
88

9-
validator.add("regex", function ({ messages }) {
9+
validator.add('regex', function ({ messages }) {
1010
return {
1111
source: `
1212
if (!(value instanceof RegExp))
1313
${this.makeError({
14-
type: "regex",
15-
actual: "value",
14+
type: 'regex',
15+
actual: 'value',
1616
messages,
1717
})}
1818

src/utilities.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { getSchemaValidator } from './schema-validator'
1+
import { getSchemaValidator } from './schema-validator';
22
import { PER_FIELD_SCHEMA, FIELD_CONFIG_SCHEMA } from './constants';
33

4-
const fieldSchemaValidator = getSchemaValidator(
5-
FIELD_CONFIG_SCHEMA,
6-
);
4+
const fieldSchemaValidator = getSchemaValidator(FIELD_CONFIG_SCHEMA);
75

8-
const perFieldSchemaValidator = getSchemaValidator(
9-
PER_FIELD_SCHEMA,
10-
);
6+
const perFieldSchemaValidator = getSchemaValidator(PER_FIELD_SCHEMA);
117

128
export function getDefaultValues(formFieldConfig) {
139
const defaultValues = {};

yarn.lock

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,6 +3642,20 @@ escodegen@^1.9.1:
36423642
optionalDependencies:
36433643
source-map "~0.6.1"
36443644

3645+
eslint-config-prettier@^6.11.0:
3646+
version "6.11.0"
3647+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz#f6d2238c1290d01c859a8b5c1f7d352a0b0da8b1"
3648+
integrity sha512-oB8cpLWSAjOVFEJhhyMZh6NOEOtBVziaqdDQ86+qhDHFbZXoRTM7pNSvFRfW/W/L/LrQ38C99J5CGuRBBzBsdA==
3649+
dependencies:
3650+
get-stdin "^6.0.0"
3651+
3652+
eslint-plugin-prettier@^3.1.3:
3653+
version "3.1.3"
3654+
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.3.tgz#ae116a0fc0e598fdae48743a4430903de5b4e6ca"
3655+
integrity sha512-+HG5jmu/dN3ZV3T6eCD7a4BlAySdN7mLIbJYo0z1cFQuI+r2DiTJEFeF68ots93PsnrMxbzIZ2S/ieX+mkrBeQ==
3656+
dependencies:
3657+
prettier-linter-helpers "^1.0.0"
3658+
36453659
eslint-scope@^4.0.3:
36463660
version "4.0.3"
36473661
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"
@@ -3942,6 +3956,11 @@ fast-deep-equal@^3.1.1:
39423956
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
39433957
integrity sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==
39443958

3959+
fast-diff@^1.1.2:
3960+
version "1.2.0"
3961+
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
3962+
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
3963+
39453964
fast-glob@^3.1.1:
39463965
version "3.2.2"
39473966
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.2.tgz#ade1a9d91148965d4bf7c51f72e1ca662d32e63d"
@@ -4289,6 +4308,11 @@ get-stdin@^4.0.1:
42894308
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
42904309
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=
42914310

4311+
get-stdin@^6.0.0:
4312+
version "6.0.0"
4313+
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
4314+
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
4315+
42924316
get-stream@^4.0.0:
42934317
version "4.1.0"
42944318
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
@@ -7377,6 +7401,18 @@ prelude-ls@~1.1.2:
73777401
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
73787402
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
73797403

7404+
prettier-linter-helpers@^1.0.0:
7405+
version "1.0.0"
7406+
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
7407+
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
7408+
dependencies:
7409+
fast-diff "^1.1.2"
7410+
7411+
prettier@^2.0.5:
7412+
version "2.0.5"
7413+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
7414+
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
7415+
73807416
pretty-format@^24.9.0:
73817417
version "24.9.0"
73827418
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"

0 commit comments

Comments
 (0)