Skip to content

Commit 8ed0042

Browse files
srmaguraAndarist
andauthored
Fix d.ts emit in @emotion/eslint-plugin (#2761)
* Put TS hacks in @emotion/eslint-plugin to make Preconstruct not error * Fixed the declaration emit for `@emotion/eslint-plugin` without casts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
1 parent f01f9bc commit 8ed0042

16 files changed

+121
-46
lines changed

packages/eslint-plugin/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"eslint": "6 || 7 || 8"
2323
},
2424
"dependencies": {
25-
"@typescript-eslint/experimental-utils": "^4.30.0"
25+
"@typescript-eslint/utils": "^5.25.0"
2626
},
2727
"devDependencies": {
2828
"@types/eslint": "^7.0.0",

packages/eslint-plugin/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styledImport from './rules/styled-import'
55
import jsxImport from './rules/jsx-import'
66
import pkgRenaming from './rules/pkg-renaming'
77

8-
export let rules = {
8+
export const rules = {
99
'import-from-emotion': importFromEmotion,
1010
'no-vanilla': noVanilla,
1111
'syntax-preference': syntaxPreference,

packages/eslint-plugin/src/rules/import-from-emotion.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/experimental-utils'
1+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'
22
import { createRule } from '../utils'
33

4-
export default createRule({
4+
const messages = {
5+
incorrectImport: `emotion's exports should be imported directly from emotion rather than from react-emotion`
6+
}
7+
8+
export default createRule<never[], keyof typeof messages>({
59
name: __filename,
610
meta: {
711
docs: {
8-
category: 'Best Practices',
912
description: 'Ensure styled is imported from @emotion/styled',
1013
recommended: false
1114
},
1215
fixable: 'code',
13-
messages: {
14-
incorrectImport: `emotion's exports should be imported directly from emotion rather than from react-emotion`
15-
},
16+
messages,
1617
schema: [],
1718
type: 'problem'
1819
},

packages/eslint-plugin/src/rules/jsx-import.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/experimental-utils'
1+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'
22
import { createRule, REPO_URL } from '../utils'
33

44
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/
@@ -9,13 +9,13 @@ const JSX_IMPORT_SOURCE_REGEX = /\*?\s*@jsxImportSource\s+([^\s]+)/
99
// to
1010
// <div css={css`color:hotpink;`} /> + import { css }
1111

12-
declare module '@typescript-eslint/experimental-utils/dist/ts-eslint/Rule' {
12+
declare module '@typescript-eslint/utils/dist/ts-eslint/Rule' {
1313
export interface SharedConfigurationSettings {
1414
react?: { pragma?: string }
1515
}
1616
}
1717

18-
interface JSXConfig {
18+
type JSXConfig = {
1919
runtime: string
2020
importSource?: string
2121
}
@@ -32,7 +32,6 @@ export default createRule<RuleOptions, keyof typeof messages>({
3232
name: __filename,
3333
meta: {
3434
docs: {
35-
category: 'Possible Errors',
3635
description: 'Ensure jsx from @emotion/react is imported',
3736
recommended: false
3837
},

packages/eslint-plugin/src/rules/no-vanilla.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { createRule } from '../utils'
22

3-
export default createRule({
3+
const messages = {
4+
vanillaEmotion: 'Vanilla emotion should not be used'
5+
}
6+
7+
export default createRule<never[], keyof typeof messages>({
48
name: __filename,
59
meta: {
610
docs: {
7-
category: 'Best Practices',
811
description: 'Ensure vanilla emotion is not used',
912
recommended: false
1013
},
11-
messages: {
12-
vanillaEmotion: 'Vanilla emotion should not be used'
13-
},
14+
messages,
1415
schema: [],
1516
type: 'problem'
1617
},

packages/eslint-plugin/src/rules/pkg-renaming.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'
1+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
22
import { createRule } from '../utils'
33

44
const simpleMappings = new Map<unknown, string>([
@@ -14,20 +14,21 @@ const simpleMappings = new Map<unknown, string>([
1414
['emotion-server', '@emotion/server']
1515
])
1616

17-
export default createRule({
17+
const messages = {
18+
renamePackage: `{{ beforeName }} has been renamed to {{ afterName }}, please import it from {{ afterName }} instead`,
19+
exportChange: `The default export of "{{ name }}" in Emotion 10 has been moved to a named export, \`css\`, from "{{ replacement }}" in Emotion 11, please import it from "{{ replacement }}"`,
20+
emotionTheming: `"emotion-theming" has been moved into "@emotion/react", please import its exports from "@emotion/react"`
21+
}
22+
23+
export default createRule<never[], keyof typeof messages>({
1824
name: __filename,
1925
meta: {
2026
docs: {
21-
category: 'Best Practices',
2227
description: 'Internal rule',
2328
recommended: false
2429
},
2530
fixable: 'code',
26-
messages: {
27-
renamePackage: `{{ beforeName }} has been renamed to {{ afterName }}, please import it from {{ afterName }} instead`,
28-
exportChange: `The default export of "{{ name }}" in Emotion 10 has been moved to a named export, \`css\`, from "{{ replacement }}" in Emotion 11, please import it from "{{ replacement }}"`,
29-
emotionTheming: `"emotion-theming" has been moved into "@emotion/react", please import its exports from "@emotion/react"`
30-
},
31+
messages,
3132
schema: [],
3233
type: 'problem'
3334
},

packages/eslint-plugin/src/rules/styled-import.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'
1+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
22
import { createRule } from '../utils'
33

4-
export default createRule({
4+
const messages = {
5+
incorrectImport: 'styled should be imported from @emotion/styled'
6+
}
7+
8+
export default createRule<never[], keyof typeof messages>({
59
name: __filename,
610
meta: {
711
docs: {
8-
category: 'Best Practices',
912
description: 'Ensure styled is imported from @emotion/styled',
1013
recommended: false
1114
},
1215
fixable: 'code',
13-
messages: {
14-
incorrectImport: 'styled should be imported from @emotion/styled'
15-
},
16+
messages,
1617
schema: [],
1718
type: 'problem'
1819
},

packages/eslint-plugin/src/rules/syntax-preference.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
AST_NODE_TYPES,
3-
TSESLint,
4-
TSESTree
5-
} from '@typescript-eslint/experimental-utils'
1+
import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils'
62
import { createRule } from '../utils'
73

84
/**
@@ -235,7 +231,6 @@ export default createRule<RuleOptions, MessageId>({
235231
name: __filename,
236232
meta: {
237233
docs: {
238-
category: 'Stylistic Issues',
239234
description: 'Choose between styles written as strings or objects',
240235
recommended: false
241236
},

packages/eslint-plugin/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ESLintUtils } from '@typescript-eslint/experimental-utils'
1+
import { ESLintUtils } from '@typescript-eslint/utils'
22
import { parse as parsePath } from 'path'
33

44
const { version } = require('../package.json')

packages/eslint-plugin/test/rules/import-from-emotion.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment node
33
*/
44

5-
import { TSESLint } from '@typescript-eslint/experimental-utils'
5+
import { TSESLint } from '@typescript-eslint/utils'
66
import rule from '../../src/rules/import-from-emotion'
77
import { espreeParser } from '../test-utils'
88

packages/eslint-plugin/test/rules/jsx-import.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment node
33
*/
44

5-
import { TSESLint } from '@typescript-eslint/experimental-utils'
5+
import { TSESLint } from '@typescript-eslint/utils'
66
import rule from '../../src/rules/jsx-import'
77
import { espreeParser } from '../test-utils'
88

packages/eslint-plugin/test/rules/no-vanilla.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment node
33
*/
44

5-
import { TSESLint } from '@typescript-eslint/experimental-utils'
5+
import { TSESLint } from '@typescript-eslint/utils'
66
import rule from '../../src/rules/no-vanilla'
77
import { espreeParser } from '../test-utils'
88

packages/eslint-plugin/test/rules/pkg-renaming.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment node
33
*/
44

5-
import { TSESLint } from '@typescript-eslint/experimental-utils'
5+
import { TSESLint } from '@typescript-eslint/utils'
66
import rule from '../../src/rules/pkg-renaming'
77
import { espreeParser } from '../test-utils'
88

packages/eslint-plugin/test/rules/styled-import.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @jest-environment node
33
*/
44

5-
import { TSESLint } from '@typescript-eslint/experimental-utils'
5+
import { TSESLint } from '@typescript-eslint/utils'
66
import rule from '../../src/rules/styled-import'
77
import { espreeParser } from '../test-utils'
88

packages/eslint-plugin/test/rules/syntax-preference.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Requirements
99
// ------------------------------------------------------------------------------
1010

11-
import { AST_NODE_TYPES, TSESLint } from '@typescript-eslint/experimental-utils'
11+
import { AST_NODE_TYPES, TSESLint } from '@typescript-eslint/utils'
1212
import rule from '../../src/rules/syntax-preference'
1313
import { espreeParser } from '../test-utils'
1414

yarn.lock

+79-2
Original file line numberDiff line numberDiff line change
@@ -6029,6 +6029,11 @@
60296029
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
60306030
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==
60316031

6032+
"@types/json-schema@^7.0.9":
6033+
version "7.0.11"
6034+
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
6035+
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
6036+
60326037
"@types/json5@^0.0.29":
60336038
version "0.0.29"
60346039
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
@@ -6391,7 +6396,7 @@
63916396
eslint-scope "^5.0.0"
63926397
eslint-utils "^2.0.0"
63936398

6394-
"@typescript-eslint/experimental-utils@4.33.0", "@typescript-eslint/experimental-utils@^4.0.1", "@typescript-eslint/experimental-utils@^4.30.0":
6399+
"@typescript-eslint/experimental-utils@4.33.0", "@typescript-eslint/experimental-utils@^4.0.1":
63956400
version "4.33.0"
63966401
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.33.0.tgz#6f2a786a4209fa2222989e9380b5331b2810f7fd"
63976402
integrity sha512-zeQjOoES5JFjTnAhI5QY7ZviczMzDptls15GFsI6jyUOq0kOf9+WonkhtlIhh0RgHRnqj5gdNxW5j1EvAyYg6Q==
@@ -6460,6 +6465,14 @@
64606465
"@typescript-eslint/types" "4.33.0"
64616466
"@typescript-eslint/visitor-keys" "4.33.0"
64626467

6468+
"@typescript-eslint/scope-manager@5.25.0":
6469+
version "5.25.0"
6470+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.25.0.tgz#e78f1484bca7e484c48782075219c82c6b77a09f"
6471+
integrity sha512-p4SKTFWj+2VpreUZ5xMQsBMDdQ9XdRvODKXN4EksyBjFp2YvQdLkyHqOffakYZPuWJUDNu3jVXtHALDyTv3cww==
6472+
dependencies:
6473+
"@typescript-eslint/types" "5.25.0"
6474+
"@typescript-eslint/visitor-keys" "5.25.0"
6475+
64636476
"@typescript-eslint/types@3.10.1":
64646477
version "3.10.1"
64656478
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.10.1.tgz#1d7463fa7c32d8a23ab508a803ca2fe26e758727"
@@ -6475,6 +6488,11 @@
64756488
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.33.0.tgz#a1e59036a3b53ae8430ceebf2a919dc7f9af6d72"
64766489
integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ==
64776490

6491+
"@typescript-eslint/types@5.25.0":
6492+
version "5.25.0"
6493+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.25.0.tgz#dee51b1855788b24a2eceeae54e4adb89b088dd8"
6494+
integrity sha512-7fWqfxr0KNHj75PFqlGX24gWjdV/FDBABXL5dyvBOWHpACGyveok8Uj4ipPX/1fGU63fBkzSIycEje4XsOxUFA==
6495+
64786496
"@typescript-eslint/typescript-estree@2.34.0":
64796497
version "2.34.0"
64806498
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz#14aeb6353b39ef0732cc7f1b8285294937cf37d5"
@@ -6528,6 +6546,31 @@
65286546
semver "^7.3.5"
65296547
tsutils "^3.21.0"
65306548

6549+
"@typescript-eslint/typescript-estree@5.25.0":
6550+
version "5.25.0"
6551+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.25.0.tgz#a7ab40d32eb944e3fb5b4e3646e81b1bcdd63e00"
6552+
integrity sha512-MrPODKDych/oWs/71LCnuO7NyR681HuBly2uLnX3r5i4ME7q/yBqC4hW33kmxtuauLTM0OuBOhhkFaxCCOjEEw==
6553+
dependencies:
6554+
"@typescript-eslint/types" "5.25.0"
6555+
"@typescript-eslint/visitor-keys" "5.25.0"
6556+
debug "^4.3.4"
6557+
globby "^11.1.0"
6558+
is-glob "^4.0.3"
6559+
semver "^7.3.7"
6560+
tsutils "^3.21.0"
6561+
6562+
"@typescript-eslint/utils@^5.25.0":
6563+
version "5.25.0"
6564+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.25.0.tgz#272751fd737733294b4ab95e16c7f2d4a75c2049"
6565+
integrity sha512-qNC9bhnz/n9Kba3yI6HQgQdBLuxDoMgdjzdhSInZh6NaDnFpTUlwNGxplUFWfY260Ya0TRPvkg9dd57qxrJI9g==
6566+
dependencies:
6567+
"@types/json-schema" "^7.0.9"
6568+
"@typescript-eslint/scope-manager" "5.25.0"
6569+
"@typescript-eslint/types" "5.25.0"
6570+
"@typescript-eslint/typescript-estree" "5.25.0"
6571+
eslint-scope "^5.1.1"
6572+
eslint-utils "^3.0.0"
6573+
65316574
"@typescript-eslint/visitor-keys@3.10.1":
65326575
version "3.10.1"
65336576
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.10.1.tgz#cd4274773e3eb63b2e870ac602274487ecd1e931"
@@ -6551,6 +6594,14 @@
65516594
"@typescript-eslint/types" "4.33.0"
65526595
eslint-visitor-keys "^2.0.0"
65536596

6597+
"@typescript-eslint/visitor-keys@5.25.0":
6598+
version "5.25.0"
6599+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.25.0.tgz#33aa5fdcc5cedb9f4c8828c6a019d58548d4474b"
6600+
integrity sha512-yd26vFgMsC4h2dgX4+LR+GeicSKIfUvZREFLf3DDjZPtqgLx5AJZr6TetMNwFP9hcKreTTeztQYBTNbNoOycwA==
6601+
dependencies:
6602+
"@typescript-eslint/types" "5.25.0"
6603+
eslint-visitor-keys "^3.3.0"
6604+
65546605
"@webassemblyjs/ast@1.9.0":
65556606
version "1.9.0"
65566607
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"
@@ -10995,6 +11046,13 @@ debug@^4.1.0:
1099511046
dependencies:
1099611047
ms "2.1.2"
1099711048

11049+
debug@^4.3.4:
11050+
version "4.3.4"
11051+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
11052+
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
11053+
dependencies:
11054+
ms "2.1.2"
11055+
1099811056
debug@~2.2.0:
1099911057
version "2.2.0"
1100011058
resolved "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
@@ -12661,6 +12719,11 @@ eslint-visitor-keys@^2.0.0:
1266112719
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
1266212720
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
1266312721

12722+
eslint-visitor-keys@^3.3.0:
12723+
version "3.3.0"
12724+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
12725+
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
12726+
1266412727
eslint-webpack-plugin@^2.5.2:
1266512728
version "2.5.4"
1266612729
resolved "https://registry.yarnpkg.com/eslint-webpack-plugin/-/eslint-webpack-plugin-2.5.4.tgz#473b84932f1a8e2c2b8e66a402d0497bf440b986"
@@ -15307,7 +15370,7 @@ globby@^10.0.0, globby@^10.0.1:
1530715370
merge2 "^1.2.3"
1530815371
slash "^3.0.0"
1530915372

15310-
globby@^11.0.1:
15373+
globby@^11.0.1, globby@^11.1.0:
1531115374
version "11.1.0"
1531215375
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
1531315376
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
@@ -17259,6 +17322,13 @@ is-glob@^3.1.0:
1725917322
dependencies:
1726017323
is-extglob "^2.1.0"
1726117324

17325+
is-glob@^4.0.3:
17326+
version "4.0.3"
17327+
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
17328+
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
17329+
dependencies:
17330+
is-extglob "^2.1.1"
17331+
1726217332
is-hexadecimal@^1.0.0:
1726317333
version "1.0.3"
1726417334
resolved "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-1.0.3.tgz#e8a426a69b6d31470d3a33a47bb825cda02506ee"
@@ -27331,6 +27401,13 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semve
2733127401
resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
2733227402
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
2733327403

27404+
semver@^7.3.7:
27405+
version "7.3.7"
27406+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
27407+
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
27408+
dependencies:
27409+
lru-cache "^6.0.0"
27410+
2733427411
semver@~5.3.0:
2733527412
version "5.3.0"
2733627413
resolved "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"

0 commit comments

Comments
 (0)