Skip to content

Commit

Permalink
chore: backport non-breaking changes from next (#607)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
G-Rath committed Jun 21, 2020
1 parent a5a3bf1 commit c179c7c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Expand Up @@ -72,6 +72,12 @@ module.exports = {
{ blankLine: 'always', prev: 'directive', next: '*' },
{ blankLine: 'any', prev: 'directive', next: 'directive' },
],

// todo: pulled from v3 of @typescript-eslint's eslint-recommended config
'prefer-spread': 'error',
'prefer-rest-params': 'error',
'prefer-const': 'error',
'no-var': 'error',
},
overrides: [
{
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -53,6 +53,8 @@
]
},
"prettier": {
"arrowParens": "avoid",
"endOfLine": "auto",
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "all"
Expand Down
4 changes: 1 addition & 3 deletions renovate.json
@@ -1,7 +1,5 @@
{
"extends": [
"config:base"
],
"extends": ["config:base"],
"lockFileMaintenance": { "enabled": true },
"rangeStrategy": "replace",
"ignorePresets": ["group:semantic-releaseMonorepo"]
Expand Down
4 changes: 4 additions & 0 deletions src/rules/__tests__/valid-title.test.ts
Expand Up @@ -19,6 +19,10 @@ ruleTester.run('disallowedWords option', rule, {
{ ignoreTypeOfDescribeName: false, disallowedWords: ['correct'] },
],
},
{
code: 'it("correctly sets the value", () => {});',
options: [{ disallowedWords: undefined }],
},
],
invalid: [
{
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-deprecated-functions.ts
Expand Up @@ -124,6 +124,7 @@ export default createRule({
},
node,
fix(fixer) {
// eslint-disable-next-line prefer-const
let [name, func] = replacement.split('.');

if (callee.property.type === AST_NODE_TYPES.Literal) {
Expand Down
18 changes: 10 additions & 8 deletions src/rules/prefer-expect-assertions.ts
Expand Up @@ -150,19 +150,21 @@ export default createRule<[], MessageIds>({
}

if (!hasOnlyOneArgument(testFuncFirstLine)) {
const report: TSESLint.ReportDescriptor<MessageIds> = {
messageId: 'assertionsRequiresOneArgument',
loc: testFuncFirstLine.callee.property.loc,
};
let { loc } = testFuncFirstLine.callee.property;
const suggest: TSESLint.ReportSuggestionArray<MessageIds> = [];

if (testFuncFirstLine.arguments.length) {
report.loc = testFuncFirstLine.arguments[1].loc;
report.suggest = [
loc = testFuncFirstLine.arguments[1].loc;
suggest.push(
suggestRemovingExtraArguments(testFuncFirstLine.arguments, 1),
];
);
}

context.report(report);
context.report({
messageId: 'assertionsRequiresOneArgument',
suggest,
loc,
});

return;
}
Expand Down
15 changes: 12 additions & 3 deletions src/rules/valid-title.ts
Expand Up @@ -37,7 +37,17 @@ const quoteStringValue = (node: StringNode): string =>
? `\`${node.quasis[0].value.raw}\``
: node.raw;

export default createRule({
type MessageIds =
| 'titleMustBeString'
| 'emptyTitle'
| 'duplicatePrefix'
| 'accidentalSpace'
| 'disallowedWord';

export default createRule<
[{ ignoreTypeOfDescribeName?: boolean; disallowedWords?: string[] }],
MessageIds
>({
name: __filename,
meta: {
docs: {
Expand All @@ -64,7 +74,6 @@ export default createRule({
disallowedWords: {
type: 'array',
items: { type: 'string' },
default: [],
},
},
additionalProperties: false,
Expand All @@ -73,7 +82,7 @@ export default createRule({
fixable: 'code',
},
defaultOptions: [{ ignoreTypeOfDescribeName: false, disallowedWords: [] }],
create(context, [{ ignoreTypeOfDescribeName, disallowedWords }]) {
create(context, [{ ignoreTypeOfDescribeName, disallowedWords = [] }]) {
const disallowedWordsRegexp = new RegExp(
`\\b(${disallowedWords.join('|')})\\b`,
'iu',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
Expand Down

0 comments on commit c179c7c

Please sign in to comment.