Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Upgrade to prettier 3 #25524

Merged
merged 15 commits into from
Jan 12, 2024
1 change: 1 addition & 0 deletions code/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'jest/no-standalone-expect': 'off',
'jest/no-done-callback': 'off',
'jest/no-deprecated-functions': 'off',
'jest/valid-expect': 'off',

'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
'eslint-comments/no-unused-disable': 'error',
Expand Down
4 changes: 2 additions & 2 deletions code/addons/a11y/src/components/Report/HighlightToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function areAllRequiredElementsHighlighted(
return highlightedCount === 0
? CheckBoxStates.UNCHECKED
: highlightedCount === elementsToHighlight.length
? CheckBoxStates.CHECKED
: CheckBoxStates.INDETERMINATE;
? CheckBoxStates.CHECKED
: CheckBoxStates.INDETERMINATE;
}

const HighlightToggle: React.FC<ToggleProps> = ({ toggleId, elementsToHighlight = [] }) => {
Expand Down
48 changes: 16 additions & 32 deletions code/addons/backgrounds/src/containers/BackgroundSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,24 @@ const createBackgroundSelectorItem = memoize(1000)(
})
);

const getDisplayedItems = memoize(10)(
(
backgrounds: Background[],
selectedBackgroundColor: string | null,
change: (arg: { selected: string; name: string }) => void
) => {
const backgroundSelectorItems = backgrounds.map(({ name, value }) =>
createBackgroundSelectorItem(
null,
name,
value,
true,
change,
value === selectedBackgroundColor
)
);

if (selectedBackgroundColor !== 'transparent') {
return [
createBackgroundSelectorItem(
'reset',
'Clear background',
'transparent',
null,
change,
false
),
...backgroundSelectorItems,
];
}
const getDisplayedItems = memoize(10)((
backgrounds: Background[],
selectedBackgroundColor: string | null,
change: (arg: { selected: string; name: string }) => void
) => {
const backgroundSelectorItems = backgrounds.map(({ name, value }) =>
createBackgroundSelectorItem(null, name, value, true, change, value === selectedBackgroundColor)
);

return backgroundSelectorItems;
if (selectedBackgroundColor !== 'transparent') {
return [
createBackgroundSelectorItem('reset', 'Clear background', 'transparent', null, change, false),
...backgroundSelectorItems,
];
}
);

return backgroundSelectorItems;
});

const DEFAULT_BACKGROUNDS_CONFIG: BackgroundsParameter = {
default: null,
Expand Down
33 changes: 18 additions & 15 deletions code/addons/viewport/src/Tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ const responsiveViewport: ViewportItem = {

const baseViewports: ViewportItem[] = [responsiveViewport];

const toLinks = memoize(50)(
(list: ViewportItem[], active: LinkBase, updateGlobals, close): Link[] => {
return list
.filter((i) => i.id !== responsiveViewport.id || active.id !== i.id)
.map((i) => {
return {
...i,
onClick: () => {
updateGlobals({ viewport: i.id });
close();
},
};
});
}
);
const toLinks = memoize(50)((
list: ViewportItem[],
active: LinkBase,
updateGlobals,
close
): Link[] => {
return list
.filter((i) => i.id !== responsiveViewport.id || active.id !== i.id)
.map((i) => {
return {
...i,
onClick: () => {
updateGlobals({ viewport: i.id });
close();
},
};
});
});

interface LinkBase {
id: string;
Expand Down
2 changes: 1 addition & 1 deletion code/builders/builder-vite/src/vite-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const dummyOptions: Options = {
builder: {},
},
options: {},
}[key]),
})[key],
} as Presets,
presetsList: [],
};
Expand Down
45 changes: 22 additions & 23 deletions code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ export default async (
externals['@storybook/blocks'] = '__STORYBOOK_BLOCKS_EMPTY_MODULE__';
}

const { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(
options
);
const { virtualModules: virtualModuleMapping, entries: dynamicEntries } =
await getVirtualModules(options);

return {
name: 'preview',
Expand Down Expand Up @@ -286,26 +285,26 @@ export default async (
}),
]
: builderOptions.useSWC
? [
new TerserWebpackPlugin<SwcOptions>({
minify: TerserWebpackPlugin.swcMinify,
terserOptions: {
sourceMap: !options.build?.test?.disableSourcemaps,
mangle: false,
keep_fnames: true,
},
}),
]
: [
new TerserWebpackPlugin({
parallel: true,
terserOptions: {
sourceMap: !options.build?.test?.disableSourcemaps,
mangle: false,
keep_fnames: true,
},
}),
],
? [
new TerserWebpackPlugin<SwcOptions>({
minify: TerserWebpackPlugin.swcMinify,
terserOptions: {
sourceMap: !options.build?.test?.disableSourcemaps,
mangle: false,
keep_fnames: true,
},
}),
]
: [
new TerserWebpackPlugin({
parallel: true,
terserOptions: {
sourceMap: !options.build?.test?.disableSourcemaps,
mangle: false,
keep_fnames: true,
},
}),
],
}
: {}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const buildTemplate = (
const firstSelector = selector.split(',')[0];
const templateReplacers: [
string | RegExp,
string | ((substring: string, ...args: any[]) => string)
string | ((substring: string, ...args: any[]) => string),
][] = [
[/(^.*?)(?=[,])/, '$1'],
[/(^\..+)/, 'div$1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class PropertyExtractor implements NgModuleMetadata {
applicationProviders?: Array<Provider | ReturnType<typeof importProvidersFrom>>;
/* eslint-enable @typescript-eslint/lines-between-class-members */

constructor(private metadata: NgModuleMetadata, private component?: any) {
constructor(
private metadata: NgModuleMetadata,
private component?: any
) {
this.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export class AttributeSelectorComponent {

selectors!: string;

constructor(public el: ElementRef, private resolver: ComponentFactoryResolver) {
constructor(
public el: ElementRef,
private resolver: ComponentFactoryResolver
) {
const factory = this.resolver.resolveComponentFactory(AttributeSelectorComponent);
this.selectors = factory.selector;
this.generatedTemplate = el.nativeElement.outerHTML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export class ClassSelectorComponent {

selectors!: string;

constructor(public el: ElementRef, private resolver: ComponentFactoryResolver) {
constructor(
public el: ElementRef,
private resolver: ComponentFactoryResolver
) {
const factory = this.resolver.resolveComponentFactory(ClassSelectorComponent);
this.selectors = factory.selector;
this.generatedTemplate = el.nativeElement.outerHTML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export class MultipleSelectorComponent {

selectors!: string;

constructor(public el: ElementRef, private resolver: ComponentFactoryResolver) {
constructor(
public el: ElementRef,
private resolver: ComponentFactoryResolver
) {
const factory = this.resolver.resolveComponentFactory(MultipleClassSelectorComponent);
this.selectors = factory.selector;
this.generatedTemplate = el.nativeElement.outerHTML;
Expand All @@ -29,7 +32,10 @@ export class MultipleClassSelectorComponent {

selectors!: string;

constructor(public el: ElementRef, private resolver: ComponentFactoryResolver) {
constructor(
public el: ElementRef,
private resolver: ComponentFactoryResolver
) {
const factory = this.resolver.resolveComponentFactory(MultipleClassSelectorComponent);
this.selectors = factory.selector;
this.generatedTemplate = el.nativeElement.outerHTML;
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/nextjs/src/babel/plugins/jsx-pragma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export default function jsxPragma({ types: t }: { types: typeof BabelTypes }): P
? // import { $import as _pragma } from '$module'
t.importSpecifier(importAs, t.identifier(state.opts.import))
: state.opts.importNamespace
? t.importNamespaceSpecifier(importAs)
: // import _pragma from '$module'
t.importDefaultSpecifier(importAs),
? t.importNamespaceSpecifier(importAs)
: // import _pragma from '$module'
t.importDefaultSpecifier(importAs),
],
t.stringLiteral(state.opts.module || 'react')
);
Expand Down
16 changes: 8 additions & 8 deletions code/frameworks/nextjs/src/babel/plugins/next-ssg-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ export default function nextTransformSsg({
p.node.type === 'ObjectProperty'
? 'value'
: p.node.type === 'RestElement'
? 'argument'
: (function () {
throw new Error('invariant');
})()
? 'argument'
: (function () {
throw new Error('invariant');
})()
) as NodePath<BabelTypes.Identifier>;
if (isIdentifierReferenced(local)) {
variableState.refs.add(local);
Expand Down Expand Up @@ -360,10 +360,10 @@ export default function nextTransformSsg({
p.node.type === 'ObjectProperty'
? 'value'
: p.node.type === 'RestElement'
? 'argument'
: (function () {
throw new Error('invariant');
})()
? 'argument'
: (function () {
throw new Error('invariant');
})()
) as NodePath<BabelTypes.Identifier>;

if (refs.has(local) && !isIdentifierReferenced(local)) {
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"jscodeshift": "^0.15.1",
"leven": "^3.1.0",
"ora": "^5.4.1",
"prettier": "^2.8.0",
"prettier": "^3.1.1",
"prompts": "^2.4.0",
"read-pkg-up": "^7.0.1",
"semver": "^7.3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('is not Nx project', () => {
() =>
({
hasStorybookBuilder: true,
} as any)
}) as any
);
});

Expand All @@ -129,7 +129,7 @@ describe('is not Nx project', () => {
project1: { root: 'project1', architect: {} },
},
rootProject: 'project1',
} as any)
}) as any
);
});

Expand All @@ -155,7 +155,7 @@ describe('is not Nx project', () => {
project2: { root: 'project2', architect: {} },
},
rootProject: null,
} as any)
}) as any
);
});

Expand Down
6 changes: 3 additions & 3 deletions code/lib/cli/src/automigrate/fixes/angular-builders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('is not Nx project', () => {
() =>
({
hasStorybookBuilder: true,
} as any)
}) as any
);
});

Expand All @@ -133,7 +133,7 @@ describe('is not Nx project', () => {
project2: { root: 'project2', architect: {} },
},
rootProject: null,
} as any)
}) as any
);
});

Expand All @@ -158,7 +158,7 @@ describe('is not Nx project', () => {
project1: { root: 'project1', architect: {} },
},
rootProject: 'project1',
} as any)
}) as any
);
});

Expand Down
16 changes: 8 additions & 8 deletions code/lib/cli/src/automigrate/fixes/new-frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ export const newFrameworks: Fix<NewFrameworkRunOptions> = {
❌ Your project should be upgraded to use the framework package ${chalk.bold(
newFrameworkPackage
)}, but we detected that you are using Vite ${chalk.bold(
viteVersion
)}, which is unsupported in ${chalk.bold(
'Storybook 7.0'
)}. Please upgrade Vite to ${chalk.bold('3.0.0 or higher')} and rerun this migration.
viteVersion
)}, which is unsupported in ${chalk.bold(
'Storybook 7.0'
)}. Please upgrade Vite to ${chalk.bold('3.0.0 or higher')} and rerun this migration.
`);
}

Expand Down Expand Up @@ -351,8 +351,8 @@ export const newFrameworks: Fix<NewFrameworkRunOptions> = {
This migration is set to update your project to use the ${chalk.magenta(
'@storybook/react-vite'
)} framework, but Storybook provides a framework package specifically for Next.js projects: ${chalk.magenta(
'@storybook/nextjs'
)}.
'@storybook/nextjs'
)}.

This package provides a better, out of the box experience for Next.js users, however it is only compatible with the Webpack 5 builder, so we can't automigrate for you, as you are using the Vite builder. If you switch this project to use Webpack 5 and rerun this migration, we can update your project.

Expand All @@ -379,8 +379,8 @@ export const newFrameworks: Fix<NewFrameworkRunOptions> = {
This migration is set to update your project to use the ${chalk.magenta(
'@storybook/svelte-webpack5'
)} framework, but Storybook provides a framework package specifically for SvelteKit projects: ${chalk.magenta(
'@storybook/sveltekit'
)}.
'@storybook/sveltekit'
)}.

This package provides a better experience for SvelteKit users, however it is only compatible with the Vite builder, so we can't automigrate for you, as you are using the Webpack builder.

Expand Down
Loading