Skip to content

Commit

Permalink
Enable type information for jest/unbound-method (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Apr 3, 2023
1 parent ce8a30c commit bcee0a8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-frogs-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/foundry': patch
---

Enabled type checking for unit test files to provide required type information to the `jest/unbound-method` rule.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"repository": "https://github.com/sumup-oss/foundry",
"author": "Felix Jung <felix.jung@sumup.com>, Connor Bär <connor.baer@sumup.com>",
"license": "Apache-2.0",
"files": ["./dist", "./CHANGELOG.md", "./CONTRIBUTING.md"],
"bin": "dist/cli/index.js",
"exports": {
"./eslint": "./dist/eslint.js",
Expand Down
60 changes: 60 additions & 0 deletions src/configs/eslint/__snapshots__/config.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ exports[`eslint with options should return a config for {
},
"extends": [
"plugin:jest/recommended",
"plugin:@typescript-eslint/recommended",
],
"files": [
"**/*.spec.*",
Expand All @@ -420,6 +421,20 @@ exports[`eslint with options should return a config for {
"**/__fixtures__/**/*",
"**/__mocks__/**/*",
],
"parserOptions": {
"ecmaFeatures": {
"modules": true,
},
"ecmaVersion": 6,
"extraFileExtensions": [
".json",
],
"project": [
"./tsconfig.json",
],
"sourceType": "module",
"tsconfigRootDir": "/project/dir",
},
"plugins": [
"jest",
],
Expand Down Expand Up @@ -1625,6 +1640,7 @@ exports[`eslint with options should return a config for {
},
"extends": [
"plugin:jest/recommended",
"plugin:@typescript-eslint/recommended",
],
"files": [
"**/*.spec.*",
Expand All @@ -1635,6 +1651,20 @@ exports[`eslint with options should return a config for {
"**/__fixtures__/**/*",
"**/__mocks__/**/*",
],
"parserOptions": {
"ecmaFeatures": {
"modules": true,
},
"ecmaVersion": 6,
"extraFileExtensions": [
".json",
],
"project": [
"./tsconfig.json",
],
"sourceType": "module",
"tsconfigRootDir": "/project/dir",
},
"plugins": [
"jest",
],
Expand Down Expand Up @@ -3208,6 +3238,7 @@ exports[`eslint with options should return a config for {
},
"extends": [
"plugin:jest/recommended",
"plugin:@typescript-eslint/recommended",
],
"files": [
"**/*.spec.*",
Expand All @@ -3218,6 +3249,20 @@ exports[`eslint with options should return a config for {
"**/__fixtures__/**/*",
"**/__mocks__/**/*",
],
"parserOptions": {
"ecmaFeatures": {
"modules": true,
},
"ecmaVersion": 6,
"extraFileExtensions": [
".json",
],
"project": [
"./tsconfig.json",
],
"sourceType": "module",
"tsconfigRootDir": "/project/dir",
},
"plugins": [
"jest",
],
Expand Down Expand Up @@ -5291,6 +5336,7 @@ exports[`eslint with options should return a config for {
},
"extends": [
"plugin:jest/recommended",
"plugin:@typescript-eslint/recommended",
],
"files": [
"**/*.spec.*",
Expand All @@ -5301,6 +5347,20 @@ exports[`eslint with options should return a config for {
"**/__fixtures__/**/*",
"**/__mocks__/**/*",
],
"parserOptions": {
"ecmaFeatures": {
"modules": true,
},
"ecmaVersion": 6,
"extraFileExtensions": [
".json",
],
"project": [
"./tsconfig.json",
],
"sourceType": "module",
"tsconfigRootDir": "/project/dir",
},
"plugins": [
"jest",
],
Expand Down
30 changes: 19 additions & 11 deletions src/configs/eslint/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ const sharedOverrides = [
},
];

const typeScriptParserOptions = {
tsconfigRootDir: process.cwd(),
project: ['./tsconfig.json'],
extraFileExtensions: ['.json'],
sourceType: 'module',
ecmaVersion: 6,
ecmaFeatures: {
modules: true,
},
};

const base = {
root: true,
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'airbnb-base'],
Expand Down Expand Up @@ -163,16 +174,7 @@ function customizeLanguage(language?: Language) {
],
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: process.cwd(),
project: ['./tsconfig.json'],
extraFileExtensions: ['.json'],
sourceType: 'module',
ecmaVersion: 6,
ecmaFeatures: {
modules: true,
},
},
parserOptions: typeScriptParserOptions,
rules: {
...sharedRules,
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down Expand Up @@ -379,9 +381,15 @@ function customizeFramework(frameworks?: Framework[]) {
overrides: [
{
files: UNIT_TEST_FILES,
extends: ['plugin:jest/recommended'],
extends: [
'plugin:jest/recommended',
// The `jest/unbound-method` rule requires type information, see
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md
'plugin:@typescript-eslint/recommended',
],
plugins: ['jest'],
env: { 'jest/globals': true },
parserOptions: typeScriptParserOptions,
rules: {
'jest/unbound-method': 'error',
},
Expand Down

0 comments on commit bcee0a8

Please sign in to comment.