Skip to content

Commit c179c7c

Browse files
authored
chore: backport non-breaking changes from next (#607)
* chore: enable eslint core rules enabled by v3 of `@typescript-eslint` * chore: target `es2015` in `tsconfig.json` This is required for using private identifiers, which are used by `@typescript-eslint` v3. We don't use `tsc` to actually build any code, so this change only affects the typechecking side of the compiler. * chore(valid-title): adjust default for `disallowedWords` option `@typescript-eslint` v3 changed the structure of their types, meaning that we need to type the options for `valid-title`. This in turn means we have to provide a direct default value for the `disallowedWords` option, in turn meaning we have to adjust our test to ensure proper coverage instead of relying on the `default` property. * chore(prefer-expect-assertions): adjust how report object is built `@typescript-eslint` v3 changed the structure of their types, meaning that the `suggest` property in `TSESLint.ReportDescriptor` is now marked as being `readonly`, so we can't assign to it. The easiest way around this is to just refactor our code to be slightly different, given it doesn't impact behaviour, performance, or clarity. * chore: apply prettier to `renovate.json` * chore: explicitly set `prettier` options
1 parent a5a3bf1 commit c179c7c

File tree

8 files changed

+37
-15
lines changed

8 files changed

+37
-15
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ module.exports = {
7272
{ blankLine: 'always', prev: 'directive', next: '*' },
7373
{ blankLine: 'any', prev: 'directive', next: 'directive' },
7474
],
75+
76+
// todo: pulled from v3 of @typescript-eslint's eslint-recommended config
77+
'prefer-spread': 'error',
78+
'prefer-rest-params': 'error',
79+
'prefer-const': 'error',
80+
'no-var': 'error',
7581
},
7682
overrides: [
7783
{

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
]
5454
},
5555
"prettier": {
56+
"arrowParens": "avoid",
57+
"endOfLine": "auto",
5658
"proseWrap": "always",
5759
"singleQuote": true,
5860
"trailingComma": "all"

renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"extends": [
3-
"config:base"
4-
],
2+
"extends": ["config:base"],
53
"lockFileMaintenance": { "enabled": true },
64
"rangeStrategy": "replace",
75
"ignorePresets": ["group:semantic-releaseMonorepo"]

src/rules/__tests__/valid-title.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ ruleTester.run('disallowedWords option', rule, {
1919
{ ignoreTypeOfDescribeName: false, disallowedWords: ['correct'] },
2020
],
2121
},
22+
{
23+
code: 'it("correctly sets the value", () => {});',
24+
options: [{ disallowedWords: undefined }],
25+
},
2226
],
2327
invalid: [
2428
{

src/rules/no-deprecated-functions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export default createRule({
124124
},
125125
node,
126126
fix(fixer) {
127+
// eslint-disable-next-line prefer-const
127128
let [name, func] = replacement.split('.');
128129

129130
if (callee.property.type === AST_NODE_TYPES.Literal) {

src/rules/prefer-expect-assertions.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,21 @@ export default createRule<[], MessageIds>({
150150
}
151151

152152
if (!hasOnlyOneArgument(testFuncFirstLine)) {
153-
const report: TSESLint.ReportDescriptor<MessageIds> = {
154-
messageId: 'assertionsRequiresOneArgument',
155-
loc: testFuncFirstLine.callee.property.loc,
156-
};
153+
let { loc } = testFuncFirstLine.callee.property;
154+
const suggest: TSESLint.ReportSuggestionArray<MessageIds> = [];
157155

158156
if (testFuncFirstLine.arguments.length) {
159-
report.loc = testFuncFirstLine.arguments[1].loc;
160-
report.suggest = [
157+
loc = testFuncFirstLine.arguments[1].loc;
158+
suggest.push(
161159
suggestRemovingExtraArguments(testFuncFirstLine.arguments, 1),
162-
];
160+
);
163161
}
164162

165-
context.report(report);
163+
context.report({
164+
messageId: 'assertionsRequiresOneArgument',
165+
suggest,
166+
loc,
167+
});
166168

167169
return;
168170
}

src/rules/valid-title.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ const quoteStringValue = (node: StringNode): string =>
3737
? `\`${node.quasis[0].value.raw}\``
3838
: node.raw;
3939

40-
export default createRule({
40+
type MessageIds =
41+
| 'titleMustBeString'
42+
| 'emptyTitle'
43+
| 'duplicatePrefix'
44+
| 'accidentalSpace'
45+
| 'disallowedWord';
46+
47+
export default createRule<
48+
[{ ignoreTypeOfDescribeName?: boolean; disallowedWords?: string[] }],
49+
MessageIds
50+
>({
4151
name: __filename,
4252
meta: {
4353
docs: {
@@ -64,7 +74,6 @@ export default createRule({
6474
disallowedWords: {
6575
type: 'array',
6676
items: { type: 'string' },
67-
default: [],
6877
},
6978
},
7079
additionalProperties: false,
@@ -73,7 +82,7 @@ export default createRule({
7382
fixable: 'code',
7483
},
7584
defaultOptions: [{ ignoreTypeOfDescribeName: false, disallowedWords: [] }],
76-
create(context, [{ ignoreTypeOfDescribeName, disallowedWords }]) {
85+
create(context, [{ ignoreTypeOfDescribeName, disallowedWords = [] }]) {
7786
const disallowedWordsRegexp = new RegExp(
7887
`\\b(${disallowedWords.join('|')})\\b`,
7988
'iu',

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2015",
44
"module": "commonjs",
55
"moduleResolution": "node",
66
"noEmit": true,

0 commit comments

Comments
 (0)