Skip to content

Commit 38fde17

Browse files
committed
upgrade to typescript eslint utils v7
1 parent 92c47e4 commit 38fde17

20 files changed

+158
-153
lines changed

lib/rules/await-interactions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export = createStorybookRule({
3232
docs: {
3333
description: 'Interactions should be awaited',
3434
categories: [CategoryId.ADDON_INTERACTIONS, CategoryId.RECOMMENDED],
35-
recommended: 'error', // or 'warn'
35+
recommended: 'strict',
3636
},
3737
messages: {
3838
interactionShouldBeAwaited: 'Interaction should be awaited: {{method}}',

lib/rules/context-in-play-function.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export = createStorybookRule({
3030
docs: {
3131
description: 'Pass a context when invoking play function of another story',
3232
categories: [CategoryId.RECOMMENDED, CategoryId.ADDON_INTERACTIONS],
33-
recommended: 'error',
33+
recommended: 'strict',
3434
},
3535
messages: {
3636
passContextToPlayFunction: 'Pass a context when invoking play function of another story',

lib/rules/csf-component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export = createStorybookRule({
2121
docs: {
2222
description: 'The component property should be set',
2323
categories: [CategoryId.CSF],
24-
recommended: 'warn',
24+
recommended: 'recommended',
2525
},
2626
messages: {
2727
missingComponentProperty: 'Missing component property.',

lib/rules/default-exports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export = createStorybookRule({
2222
docs: {
2323
description: 'Story files should have a default export',
2424
categories: [CategoryId.CSF, CategoryId.RECOMMENDED],
25-
recommended: 'error',
25+
recommended: 'strict',
2626
},
2727
messages: {
2828
shouldHaveDefaultExport: 'The file should have a default export.',

lib/rules/hierarchy-separator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export = createStorybookRule({
2323
docs: {
2424
description: 'Deprecated hierarchy separator in title property',
2525
categories: [CategoryId.CSF, CategoryId.RECOMMENDED],
26-
recommended: 'warn',
26+
recommended: 'recommended',
2727
},
2828
messages: {
2929
useCorrectSeparators: 'Use correct separators',

lib/rules/meta-inline-properties.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export = createStorybookRule({
2525
description: 'Meta should only have inline properties',
2626
categories: [CategoryId.CSF, CategoryId.RECOMMENDED],
2727
excludeFromConfig: true,
28-
recommended: 'error',
28+
recommended: 'strict',
2929
},
3030
messages: {
3131
metaShouldHaveInlineProperties: 'Meta should only have inline properties: {{property}}',

lib/rules/no-redundant-story-name.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export = createStorybookRule({
3232
docs: {
3333
description: 'A story should not have a redundant name property',
3434
categories: [CategoryId.CSF, CategoryId.RECOMMENDED],
35-
recommended: 'warn',
35+
recommended: 'recommended',
3636
},
3737
messages: {
3838
removeRedundantName: 'Remove redundant name',

lib/rules/no-stories-of.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export = createStorybookRule({
1818
docs: {
1919
description: 'storiesOf is deprecated and should not be used',
2020
categories: [CategoryId.CSF_STRICT],
21-
recommended: 'error',
21+
recommended: 'strict',
2222
},
2323
messages: {
2424
doNotUseStoriesOf: 'storiesOf is deprecated and should not be used',

lib/rules/no-title-property-in-meta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export = createStorybookRule({
2323
docs: {
2424
description: 'Do not define a title in meta',
2525
categories: [CategoryId.CSF_STRICT],
26-
recommended: 'error',
26+
recommended: 'strict',
2727
},
2828
messages: {
2929
removeTitleInMeta: 'Remove title property from meta',

lib/rules/no-uninstalled-addons.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export = createStorybookRule({
3939
description:
4040
'This rule identifies storybook addons that are invalid because they are either not installed or contain a typo in their name.',
4141
categories: [CategoryId.RECOMMENDED],
42-
recommended: 'error', // or 'error'
42+
recommended: 'strict',
4343
},
4444
messages: {
4545
addonIsNotInstalled: `The {{ addonName }} is not installed in {{packageJsonPath}}. Did you forget to install it or is your package.json in a different location?`,

lib/rules/prefer-pascal-case.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { getDescriptor, getMetaObjectExpression } from '../utils'
1010
import { isIdentifier, isVariableDeclaration } from '../utils/ast'
1111
import { CategoryId } from '../utils/constants'
1212
import { createStorybookRule } from '../utils/create-storybook-rule'
13-
import { Scope } from '@typescript-eslint/utils/dist/ts-eslint-scope'
1413

1514
//------------------------------------------------------------------------------
1615
// Rule Definition
@@ -26,7 +25,7 @@ export = createStorybookRule({
2625
docs: {
2726
description: 'Stories should use PascalCase',
2827
categories: [CategoryId.RECOMMENDED],
29-
recommended: 'warn',
28+
recommended: 'stylistic',
3029
},
3130
messages: {
3231
convertToPascalCase: 'Use pascal case',
@@ -55,15 +54,16 @@ export = createStorybookRule({
5554
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
5655
}
5756
const getModuleScope = (): TSESLint.Scope.Scope | undefined => {
58-
// @ts-expect-error TODO: when we will upgrade `@typescript-eslint/utils` v7.x from v5.x on this package, we should resolve type definion with latest version.
59-
// In `@typescript-eslint/utils` v5.x, cannot resolve of `sourceCode`, because type definition is not still provide from that version.
6057
const { sourceCode } = context
6158

6259
// Compatibility implementation for eslint v8.x and v9.x or later
6360
// see https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
61+
// @ts-expect-error keep it for compatibility with eslint v8.x
6462
if (sourceCode.getScope) {
6563
// for eslint v9.x or later
66-
return sourceCode.scopeManager.scopes.find((scope: Scope) => scope.type === 'module')
64+
return sourceCode.scopeManager?.scopes?.find(
65+
(scope: TSESLint.Scope.Scope) => scope.type === 'module'
66+
)
6767
} else {
6868
// for eslint v8.x
6969
return context

lib/rules/story-exports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export = createStorybookRule({
2727
docs: {
2828
description: 'A story file must contain at least one story export',
2929
categories: [CategoryId.RECOMMENDED, CategoryId.CSF],
30-
recommended: 'error',
30+
recommended: 'strict',
3131
},
3232
messages: {
3333
shouldHaveStoryExport: 'The file should have at least one story export',

lib/rules/use-storybook-expect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export = createStorybookRule<TDefaultOptions, string>({
2828
docs: {
2929
description: 'Use expect from `@storybook/jest`',
3030
categories: [CategoryId.ADDON_INTERACTIONS, CategoryId.RECOMMENDED],
31-
recommended: 'error',
31+
recommended: 'strict',
3232
},
3333
messages: {
3434
updateImports: 'Update imports',

lib/rules/use-storybook-testing-library.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export = createStorybookRule({
2121
docs: {
2222
description: 'Do not use testing-library directly on stories',
2323
categories: [CategoryId.ADDON_INTERACTIONS, CategoryId.RECOMMENDED],
24-
recommended: 'error',
24+
recommended: 'strict',
2525
},
2626
schema: [],
2727
messages: {

lib/types/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ export type RuleModule = TSESLint.RuleModule<'', []> & {
77

88
// These 2 types are copied from @typescript-eslint/experimental-utils' CreateRuleMeta
99
// and modified to our needs
10-
export type StorybookRuleMetaDocs = Omit<TSESLint.RuleMetaDataDocs, 'url'> & {
10+
export type StorybookRuleMetaDocs<TOptions extends readonly unknown[]> = Omit<
11+
TSESLint.RuleMetaDataDocs<TOptions>,
12+
'url'
13+
> & {
1114
/**
1215
* Whether or not this rule should be excluded from linter config
1316
*/
@@ -18,17 +21,17 @@ export type StorybookRuleMetaDocs = Omit<TSESLint.RuleMetaDataDocs, 'url'> & {
1821
categories?: CategoryId[]
1922
}
2023

21-
export type StorybookRuleMeta<TMessageIds extends string> = Omit<
22-
TSESLint.RuleMetaData<TMessageIds>,
23-
'docs'
24-
> & {
25-
docs: StorybookRuleMetaDocs
24+
export type StorybookRuleMeta<
25+
TMessageIds extends string,
26+
TOptions extends readonly unknown[],
27+
> = Omit<TSESLint.RuleMetaData<TMessageIds, TOptions>, 'docs'> & {
28+
docs: StorybookRuleMetaDocs<TOptions>
2629
}
2730

2831
// Comment out for testing purposes:
2932
// const docs: StorybookRuleMetaDocs = {
3033
// description: 'bla',
31-
// recommended: 'error',
34+
// recommended: 'strict',
3235
// }
3336

3437
// const meta: StorybookRuleMeta<'someId'> = {

lib/utils/create-storybook-rule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function createStorybookRule<
1313
...remainingConfig
1414
}: Readonly<{
1515
name: string
16-
meta: StorybookRuleMeta<TMessageIds>
16+
meta: StorybookRuleMeta<TMessageIds, TOptions>
1717
defaultOptions: Readonly<TOptions>
1818
create: (
1919
context: Readonly<TSESLint.RuleContext<TMessageIds, TOptions>>,

lib/utils/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export const getMetaObjectExpression = (
2222
context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>
2323
) => {
2424
let meta: TSESTree.ExportDefaultDeclaration['declaration'] | null = node.declaration
25-
// @ts-expect-error TODO: when we will upgrade `@typescript-eslint/utils` v7.x from v5.x on this package, we should resolve type definion with latest version.
26-
// In `@typescript-eslint/utils` v5.x, cannot resolve of `sourceCode`, because type definition is not still provide from that version.
2725
const { sourceCode } = context
2826
if (isIdentifier(meta)) {
2927
// Compatibility implementation for eslint v8.x and v9.x or later

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"dependencies": {
5555
"@storybook/csf": "^0.0.1",
56-
"@typescript-eslint/utils": "^5.62.0",
56+
"@typescript-eslint/utils": "^7.15.0",
5757
"ts-dedent": "^2.2.0"
5858
},
5959
"devDependencies": {
@@ -63,8 +63,8 @@
6363
"@types/node": "^18.19.17",
6464
"@types/semver": "^7.5.8",
6565
"@types/requireindex": "^1.2.4",
66-
"@typescript-eslint/eslint-plugin": "^5.62.0",
67-
"@typescript-eslint/parser": "^5.62.0",
66+
"@typescript-eslint/eslint-plugin": "^7.15.0",
67+
"@typescript-eslint/parser": "^7.15.0",
6868
"auto": "^11.1.6",
6969
"eslint": "^8.56.0",
7070
"eslint-config-prettier": "^9.1.0",

0 commit comments

Comments
 (0)