Skip to content

Commit 355a175

Browse files
committed
Removed prettier
@Stylistic achieves a lot of better recommendations than prettier
1 parent 0a71c9b commit 355a175

File tree

11 files changed

+470
-221
lines changed

11 files changed

+470
-221
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ node_modules/
77
coverage/
88
!.eslintrc.js
99
!.prettierrc.js
10+
!*.js
11+
!*.ts
1012
!.vscode/*.json

.eslintrc.js

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,124 @@
1+
// @ts-check
2+
const stylistic = require('@stylistic/eslint-plugin');
3+
14
const off = 'off';
25

36
const warn = 'warn';
47

58
const error = 'error';
69

710
const TEST_ONLY_IMPORTS = ['fast-check', 'jest', 'eslint', 'prettier'];
11+
const customized = stylistic.configs.customize({
12+
// the following options are the default values
13+
semi: true,
14+
blockSpacing: true,
15+
});
16+
17+
/**
18+
* set of typescript-eslint any rules
19+
* @param {string} level
20+
* @returns
21+
*/
22+
const any_rules = (level) => {
23+
return {
24+
'@typescript-eslint/no-unsafe-return': level,
25+
'@typescript-eslint/no-var-requires': level,
26+
'@typescript-eslint/no-unsafe-member-access': level,
27+
'@typescript-eslint/no-unsafe-argument': level,
28+
'@typescript-eslint/no-unsafe-call': level,
29+
'@typescript-eslint/no-explicit-any': level,
30+
};
31+
};
832

933
module.exports = {
1034
extends: [
1135
'eslint:recommended',
1236
'plugin:@typescript-eslint/eslint-recommended',
1337
'plugin:@typescript-eslint/recommended',
1438
'plugin:@typescript-eslint/recommended-requiring-type-checking',
15-
'plugin:prettier/recommended',
1639
'plugin:import/errors',
1740
'plugin:import/warnings',
1841
'plugin:import/typescript',
42+
// 'plugin:prettier/recommended',
43+
// 'prettier',
1944
],
2045
env: {
2146
node: true,
2247
},
23-
plugins: ['@typescript-eslint/eslint-plugin'],
48+
plugins: [
49+
'@typescript-eslint/eslint-plugin',
50+
'@stylistic', // stylistic rules were migrated here
51+
],
2452
parser: '@typescript-eslint/parser',
2553
parserOptions: {
2654
ecmaVersion: 2022,
2755
sourceType: 'module',
2856
tsconfigRootDir: __dirname,
29-
project: ['./tsconfig.eslint.json'],
57+
project: [
58+
'./tsconfig.eslint.json',
59+
'./tsconfig.json',
60+
'/tsconfig.prod.json',
61+
],
3062
},
3163
rules: {
32-
'import/no-extraneous-dependencies': warn,
64+
...customized.rules,
65+
'import/no-extraneous-dependencies': error,
3366
'no-console': error,
67+
'@typescript-eslint/return-await': ['error', 'always'],
3468
'no-unused-vars': off,
3569
'@typescript-eslint/no-unused-vars': error,
36-
eqeqeq: [error, 'smart'],
70+
'eqeqeq': [error, 'smart'],
3771
'no-else-return': [
3872
error,
3973
{
4074
allowElseIf: true,
4175
},
4276
],
77+
'@typescript-eslint/require-await': error,
4378
'@typescript-eslint/unbound-method': [
4479
error,
4580
{
4681
ignoreStatic: true,
4782
},
4883
],
84+
// See https://github.com/orgs/react-hook-form/discussions/8622#discussioncomment-4060570
85+
'@typescript-eslint/no-misused-promises': [
86+
error,
87+
{
88+
checksVoidReturn: {
89+
attributes: false,
90+
},
91+
},
92+
],
4993
'no-restricted-imports': [
5094
'error',
5195
{
5296
paths: TEST_ONLY_IMPORTS.map((name) => {
5397
return { name, message: `${name} is only available during testing` };
5498
}),
55-
patterns: TEST_ONLY_IMPORTS.map((dep) => `${dep}/*`),
99+
patterns: TEST_ONLY_IMPORTS.map(dep => `${dep}/*`),
56100
},
57101
],
58-
camelcase: off,
59-
'require-await': off,
60-
'@typescript-eslint/require-await': off,
61-
'@typescript-eslint/indent': off,
62102
'@typescript-eslint/explicit-member-accessibility': warn,
63-
'@typescript-eslint/no-explicit-any': off,
64-
'@typescript-eslint/no-unsafe-argument': off,
65-
'@typescript-eslint/no-unsafe-return': off,
66-
'@typescript-eslint/no-unsafe-assignment': off,
103+
'@typescript-eslint/no-explicit-any': warn,
67104
'@typescript-eslint/explicit-function-return-type': off,
68-
'@typescript-eslint/no-var-requires': off,
105+
// '@typescript-eslint/no-var-requires': off,
106+
69107
'@typescript-eslint/no-empty-function': off,
108+
70109
'@typescript-eslint/no-floating-promises': error,
71110
},
72111
overrides: [
73112
{
74-
files: ['*.ts', '*.tsx'],
75-
rules: {},
113+
files: ['.*.js', '.*.cjs', '*.config.cjs', '*.config.js', '*.config.ts'],
114+
env: {
115+
node: true,
116+
},
117+
rules: {
118+
'no-restricted-imports': off,
119+
// Consider if this is too leanient for tests
120+
...any_rules('off'),
121+
},
76122
},
77123
{
78124
// TESTING CONFIGURATION
@@ -87,16 +133,13 @@ module.exports = {
87133
'__tests__/**/*.ts',
88134
'jest.*.js',
89135
'jest.*.ts',
90-
'.*.ts',
91-
'.*.js',
92136
],
93137

94138
// https://eslint.org/docs/user-guide/configuring#specifying-environments
95139
env: {
96140
jest: true,
97141
},
98142

99-
// Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
100143
extends: ['plugin:jest/recommended'],
101144
plugins: ['jest'],
102145
rules: {
@@ -107,6 +150,7 @@ module.exports = {
107150
assertFunctionNames: ['expect', 'fc.assert'],
108151
},
109152
],
153+
...any_rules('off'),
110154
},
111155
},
112156
],

.prettierrc.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"editor.formatOnSave": true,
77
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
8-
"[javascript]": {
8+
"[javascript,typescript]": {
99
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
1010
},
1111
"jest.jestCommandLine": "npm test -- ",

__tests__/replace.test.ts

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,84 @@ const EachSimpleType = [
66
['integers', fc.integer()],
77
] as const;
88

9-
describe.each(EachSimpleType)('Simple replacements works for %p', (_, arb: Arbitrary<any>) => {
10-
test('Should replace simple types', () => {
11-
fc.assert(
12-
fc.property(arb, fc.func(arb), (s, f) => {
13-
return replace(f, (t: string): t is any => true)(s) === f(s);
14-
}),
15-
);
16-
});
17-
});
9+
describe.each(EachSimpleType)(
10+
'Simple replacements works for %p',
11+
(_, arb: Arbitrary<any>) => {
12+
test('Should replace simple types', () => {
13+
fc.assert(
14+
fc.property(arb, fc.func(arb), (s, f) => {
15+
return replace(f, (t: string): t is any => true)(s) === f(s);
16+
}),
17+
);
18+
});
19+
},
20+
);
1821

19-
describe.each(EachSimpleType)('Simple replacements works for arrays of %p', (_, arb: Arbitrary<any>) => {
20-
test('Should replace only elements', () => {
21-
fc.assert(
22-
fc.property(fc.array(arb), fc.func(arb), (arr, f) => {
23-
const obtainedResult = replace(f, (t): t is any => !Array.isArray(t))(arr);
24-
const realResult = arr.map((v) => f(v));
25-
expect(obtainedResult).toStrictEqual(realResult);
26-
}),
27-
);
28-
});
29-
});
22+
describe.each(EachSimpleType)(
23+
'Simple replacements works for arrays of %p',
24+
(_, arb: Arbitrary<any>) => {
25+
test('Should replace only elements', () => {
26+
fc.assert(
27+
fc.property(fc.array(arb), fc.func(arb), (arr, f) => {
28+
const obtainedResult = replace(
29+
f,
30+
(t): t is any => !Array.isArray(t),
31+
)(arr);
32+
const realResult = arr.map(v => f(v));
33+
expect(obtainedResult).toStrictEqual(realResult);
34+
}),
35+
);
36+
});
37+
},
38+
);
3039

31-
describe.each(EachSimpleType)('Simple replacements works for objects of %p', (_, arb: Arbitrary<any>) => {
32-
test('Should replace only properties', () => {
33-
fc.assert(
34-
fc.property(fc.dictionary(fc.string(), arb), fc.func(arb), (obj, f) => {
35-
const realResult = Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, f(v)]));
36-
const obtainedResult = replace(f, (t): t is any => !Array.isArray(t) && typeof t !== 'object')(obj);
40+
describe.each(EachSimpleType)(
41+
'Simple replacements works for objects of %p',
42+
(_, arb: Arbitrary<any>) => {
43+
test('Should replace only properties', () => {
44+
fc.assert(
45+
fc.property(fc.dictionary(fc.string(), arb), fc.func(arb), (obj, f) => {
46+
const realResult = Object.fromEntries(
47+
Object.entries(obj).map(([k, v]) => [k, f(v)]),
48+
);
49+
const obtainedResult = replace(
50+
f,
51+
(t): t is any => !Array.isArray(t) && typeof t !== 'object',
52+
)(obj);
3753

38-
expect(obtainedResult).toStrictEqual(realResult);
39-
}),
40-
);
41-
});
42-
});
54+
expect(obtainedResult).toStrictEqual(realResult);
55+
}),
56+
);
57+
});
58+
},
59+
);
4360

4461
describe('Ignoring values', () => {
62+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4563
const f = (v: any) => {
4664
throw new Error();
4765
};
4866
test('should leave json objects alone', () => {
4967
const throwOnReplace = replace(f, (t): t is any => false);
5068
fc.assert(
5169
fc.property(fc.json(), (json) => {
52-
expect(() => expect(throwOnReplace(json)).toStrictEqual(json)).not.toThrow();
70+
expect(() =>
71+
expect(throwOnReplace(json)).toStrictEqual(json),
72+
).not.toThrow();
5373
}),
5474
);
5575
});
5676

5777
test('Should leave numbers unchanged when searching for strings', () => {
58-
const throwOnReplace = replace(f, (t): t is string => typeof t === 'string');
59-
const objectArbitrary = fc.object({ maxDepth: 4, withTypedArray: true, values: [fc.integer()] });
78+
const throwOnReplace = replace(
79+
f,
80+
(t): t is string => typeof t === 'string',
81+
);
82+
const objectArbitrary = fc.object({
83+
maxDepth: 4,
84+
withTypedArray: true,
85+
values: [fc.integer()],
86+
});
6087
fc.assert(
6188
fc.property(objectArbitrary, (obj) => {
6289
expect(() => throwOnReplace(obj)).not.toThrow();

jest.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import type { JestConfigWithTsJest } from 'ts-jest';
22

33
const config: JestConfigWithTsJest = {
44
preset: 'ts-jest',
5-
testRegex: ['/tests/.*tests?.[jt]sx?', '/__tests__/.*tests?.[jt]sx?', '.*.(spec|test).[jt]sx?'],
5+
testRegex: [
6+
'/tests/.*tests?.[jt]sx?',
7+
'/__tests__/.*tests?.[jt]sx?',
8+
'.*.(spec|test).[jt]sx?',
9+
],
610
// I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe.
711
// We can change this if we consider it useful to run the spec tests when the code is transpiled to javascript
812
testPathIgnorePatterns: ['node_modules', 'build/'],

jest.setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import fc from 'fast-check';
99
const JestTimeoutMs = 60000;
1010
const FcTimeoutMs = Math.floor(0.8 * JestTimeoutMs);
1111

12-
const verbose =
13-
process.env.DEBUG === undefined
12+
const verbose
13+
= process.env.DEBUG === undefined
1414
? fc.VerbosityLevel.None
1515
: process.env.DEBUG !== '*'
1616
? fc.VerbosityLevel.Verbose

0 commit comments

Comments
 (0)