Skip to content

Commit

Permalink
Merge pull request #1051 from chromaui/cody/cap-2225-enable-unicornno…
Browse files Browse the repository at this point in the history
…-array-callback-reference

Enable `unicorn/no-array-callback-reference` ESLint rule
  • Loading branch information
codykaup authored Sep 13, 2024
2 parents b3c8ccf + 87ab789 commit e39417c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 20 deletions.
6 changes: 4 additions & 2 deletions bin-src/trim-stats-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export async function main([statsFile = './storybook-static/preview-stats.json']
try {
const stats = await readStatsFile(statsFile);
const trimmedModules = stats.modules
.filter(isUserCode)
.filter((module) => isUserCode(module))
.map(({ id, name, modules, reasons }) => {
const trimmedReasons = dedupe(reasons.filter(isUserCode).map((r) => r.moduleName))
const trimmedReasons = dedupe(
reasons.filter((reason) => isUserCode(reason)).map((r) => r.moduleName)
)
.filter((n) => n !== name)
.map((moduleName) => ({ moduleName }));
return {
Expand Down
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export default [
'unicorn/no-null': 'off',
'unicorn/better-regex': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-spread': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion node-src/lib/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const parseNexec = ((agent, args) => {
};

const command = map[agent];
return command.replace('{0}', args.map(quote).join(' ')).trim();
return command.replace('{0}', args.map((c) => quote(c)).join(' ')).trim();
}) as Runner;

export async function getE2EBuildCommand(
Expand Down
2 changes: 1 addition & 1 deletion node-src/lib/findChangedPackageFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const findChangedPackageFiles = async (
) => {
const changedManifestFiles = await Promise.all(
packageMetadataChanges.map(({ changedFiles, commit }) => {
const changedManifestFiles = changedFiles.filter(isPackageMetadataFile);
const changedManifestFiles = changedFiles.filter((f) => isPackageMetadataFile(f));
if (!changedManifestFiles) return [];
return getManifestFilesWithChangedDependencies(changedManifestFiles, commit);
})
Expand Down
12 changes: 6 additions & 6 deletions node-src/lib/getDependentStoryFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function getDependentStoryFiles(
`/virtual:/@storybook/builder-vite/vite-app.js`,
// rspack builder
`./node_modules/.cache/storybook/default/dev-server/storybook-stories.js`,
].map(normalize)
].map((file) => normalize(file))
);

const modulesByName = new Map<NormalizedName, Module>();
Expand Down Expand Up @@ -192,7 +192,7 @@ export async function getDependentStoryFiles(
// Convert dependency names into their corresponding files which occur in the stats file.
...changedDependencies.flatMap((packageName) => nodeModules.get(packageName) || []),
...changedFiles,
].filter(untrace);
].filter((file) => untrace(file));
const tracedPaths = new Set<string>();
const affectedModuleIds = new Set<string | number>();
const checkedIds = {};
Expand All @@ -211,14 +211,14 @@ export async function getDependentStoryFiles(
bailReason: undefined,
};

const changedPackageLockFiles = tracedFiles.filter(isPackageLockFile);
const changedPackageLockFiles = tracedFiles.filter((file) => isPackageLockFile(file));

if (nodeModules.size === 0 && changedDependencies.length > 0) {
// If we didn't find any node_modules in the stats file, it's probably incomplete and we can't
// trace changed dependencies, so we bail just in case.
ctx.turboSnap.bailReason = {
changedPackageFiles: ctx.git.changedFiles
.filter(isPackageManifestFile)
.filter((file) => isPackageManifestFile(file))
.concat(changedPackageLockFiles),
};
}
Expand Down Expand Up @@ -248,7 +248,7 @@ export async function getDependentStoryFiles(
// Queue this id for tracing
toCheck.push([id, [...tracePath, id]]);

if (reasonsById.get(id).some(isCsfGlob)) {
if (reasonsById.get(id).some((reason) => isCsfGlob(reason))) {
affectedModuleIds.add(id);
tracedPaths.add([...tracePath, id].map((pid) => namesById.get(pid)).join('\n'));
}
Expand All @@ -267,7 +267,7 @@ export async function getDependentStoryFiles(
checkedIds[id] = true;
reasonsById
.get(id)
.filter(untrace)
.filter((file) => untrace(file))
.map((reason) => traceName(reason, tracePath));
}
const affectedModules = Object.fromEntries(
Expand Down
10 changes: 5 additions & 5 deletions node-src/lib/getStorybookMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const resolvePackageJson = (pkg: string) => {

const findDependency = (
{ dependencies, devDependencies, peerDependencies },
predicate: Parameters<typeof Array.prototype.find>[0]
predicate: (key: string) => string
) => [
Object.entries(dependencies || {}).find(predicate),
Object.entries(devDependencies || {}).find(predicate),
Object.entries(peerDependencies || {}).find(predicate),
Object.keys(dependencies || {}).find((dependency) => predicate(dependency)),
Object.keys(devDependencies || {}).find((dependency) => predicate(dependency)),
Object.keys(peerDependencies || {}).find((dependency) => predicate(dependency)),
];

const getDependencyInfo = ({ packageJson, log }, dependencyMap: Record<string, string>) => {
const [dep, devDep, peerDep] = findDependency(packageJson, ([key]) => dependencyMap[key]);
const [dep, devDep, peerDep] = findDependency(packageJson, (key) => dependencyMap[key]);
const [pkg, version] = dep || devDep || peerDep || [];
const dependency = viewLayers[pkg];

Expand Down
2 changes: 1 addition & 1 deletion node-src/lib/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const invert = (promise: Promise<any>) =>
new Promise<any>((resolve, reject) => promise.then(reject, resolve));

export const raceFulfilled = <T>(promises: Promise<T>[]): Promise<T> =>
invert(Promise.all(promises.map(invert)).then((arr) => arr[0]));
invert(Promise.all(promises.map((promise) => invert(promise))).then((arr) => arr[0]));

export const timeout = (ms: number) =>
new Promise((_, rej) => {
Expand Down
2 changes: 1 addition & 1 deletion node-src/tasks/gitInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const setGitInfo = async (ctx: Context, task: Task) => {
({ build, changedFiles, replacementBuild }) => {
const metadataFiles = changedFiles
.filter((f) => !untraced.some((glob) => matchesFile(glob, f)))
.filter(isPackageMetadataFile);
.filter((f) => isPackageMetadataFile(f));

return metadataFiles.length > 0
? [{ changedFiles: metadataFiles, commit: replacementBuild?.commit ?? build.commit }]
Expand Down
6 changes: 5 additions & 1 deletion node-src/ui/messages/errors/uploadFailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { dedent } from 'ts-dedent';
import { FileDesc, TargetInfo } from '../../../types';
import { error as icon } from '../../components/icons';

const encode = (path: string) => path.split('/').map(encodeURIComponent).join('/');
const encode = (path: string) =>
path
.split('/')
.map((component) => encodeURIComponent(component))
.join('/');

export function uploadFailed({ target }: { target: FileDesc & TargetInfo }, debug = false) {
const diagnosis =
Expand Down
2 changes: 1 addition & 1 deletion node-src/ui/messages/info/listingStories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const snapshotRow = ({ spec }: { spec: Spec }) =>
export default (snapshots: { spec: Spec }[]) =>
dedent(chalk`
{bold Listing available stories:}
${snapshots.map(snapshotRow).join('\n')}
${snapshots.map((snapshot) => snapshotRow(snapshot)).join('\n')}
${info} Use {bold --only-story-names} to run a build for a specific component or story.
Globs are supported, for example: {bold --only-story-names "${
Expand Down

0 comments on commit e39417c

Please sign in to comment.