Skip to content

Commit

Permalink
Merge pull request #29266 from storybookjs/norbert/eslint-depend-plugin
Browse files Browse the repository at this point in the history
Build: Disallowed certain packages via ESlint
  • Loading branch information
ndelangen authored Oct 7, 2024
2 parents e33f671 + 581bd12 commit b3d4370
Show file tree
Hide file tree
Showing 71 changed files with 155 additions and 6 deletions.
1 change: 1 addition & 0 deletions code/builders/builder-vite/src/list-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isAbsolute, join } from 'node:path';
import { commonGlobOptions, normalizeStories } from 'storybook/internal/common';
import type { Options } from 'storybook/internal/types';

// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import slash from 'slash';

Expand Down
4 changes: 2 additions & 2 deletions code/core/src/common/js-package-manager/JsPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { existsSync, readFileSync } from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';

import type { CommonOptions } from 'execa';
import { execaCommand, execaCommandSync } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { type CommonOptions, execaCommand, execaCommandSync } from 'execa';
import picocolors from 'picocolors';
import { gt, satisfies } from 'semver';
import invariant from 'tiny-invariant';
Expand Down
1 change: 1 addition & 0 deletions code/core/src/common/utils/validate-configuration-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'node:path';
import { once } from '@storybook/core/node-logger';
import { MainFileMissingError } from '@storybook/core/server-errors';

// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import slash from 'slash';
import { dedent } from 'ts-dedent';
Expand Down
1 change: 1 addition & 0 deletions code/core/src/core-server/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class StoryIndexGenerator {
const fullGlob = slash(join(specifier.directory, specifier.files));

// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

const files = await globby(fullGlob, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { describe, expect, it, vi } from 'vitest';
import { normalizeStoriesEntry } from '@storybook/core/common';
import { type StoriesEntry } from '@storybook/core/types';

// eslint-disable-next-line depend/ban-dependencies
import { glob as globOriginal } from 'glob';
import slash from 'slash';

Expand Down
1 change: 1 addition & 0 deletions code/core/src/core-server/utils/remove-mdx-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isAbsolute, join, relative } from 'node:path';
import { commonGlobOptions, normalizeStories } from '@storybook/core/common';
import type { Options, StoriesEntry } from '@storybook/core/types';

// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import slash from 'slash';

Expand Down
1 change: 1 addition & 0 deletions code/core/src/core-server/utils/search-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function searchFiles({
fileExtensions?: string[];
}): Promise<SearchResult> {
// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby, isDynamicPattern } = await import('globby');

const hasSearchSpecialGlobChars = isDynamicPattern(searchQuery, { cwd });
Expand Down
1 change: 1 addition & 0 deletions code/core/src/core-server/utils/watch-story-specifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function watchStorySpecifiers(
);

// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

// glob only supports forward slashes
Expand Down
1 change: 1 addition & 0 deletions code/core/src/telemetry/get-portable-stories-usage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';

import { createFileSystemCache, resolvePathInStorybookCache } from '../common';
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli-storybook/src/automigrate/fixes/mdx-1-to-3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const mdx1to3: Fix<Mdx1to3Options> = {

async check() {
// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

const storiesMdxFiles = await globby('./!(node_modules)**/*.(story|stories).mdx');
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli-storybook/src/automigrate/fixes/mdx-gfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const mdxgfm: Fix<Options> = {
}

// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

const files = await globby(pattern, commonGlobOptions(pattern));
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli-storybook/src/automigrate/fixes/mdx-to-csf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { StoriesEntry } from 'storybook/internal/types';

import { runCodemod } from '@storybook/codemod';

// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import picocolors from 'picocolors';
import { prompt } from 'prompts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const missingStorybookDependencies: Fix<MissingStorybookDependenciesOptio

async check({ packageManager }) {
// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

const result = await checkInstallations(packageManager, consolidatedPackages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest';
import type { JsPackageManager } from 'storybook/internal/common';
import type { StorybookConfig } from 'storybook/internal/types';

// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';

import { removeReactDependency } from './prompt-remove-react';
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli-storybook/src/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Options {
export const warn = async ({ hasTSDependency }: Options) => {
if (!hasTSDependency) {
// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

const files = await globby(['**/*.@(ts|tsx)', '!**/node_modules', '!**/*.d.ts']);
Expand Down
1 change: 1 addition & 0 deletions code/lib/codemod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function runCodemod(
}

// Dynamically import globby because it is a pure ESM module
// eslint-disable-next-line depend/ban-dependencies
const { globby } = await import('globby');

const files = await globby([glob, '!**/node_modules', '!**/dist']);
Expand Down
1 change: 1 addition & 0 deletions code/lib/create-storybook/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { JsPackageManager } from 'storybook/internal/common';
import { getPackageDetails, versions as packageVersions } from 'storybook/internal/common';
import type { SupportedFrameworks } from 'storybook/internal/types';

// eslint-disable-next-line depend/ban-dependencies
import ora from 'ora';
import invariant from 'tiny-invariant';
import { dedent } from 'ts-dedent';
Expand Down
1 change: 1 addition & 0 deletions code/lib/create-storybook/src/scaffold-new-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GenerateNewProjectOnInitError } from 'storybook/internal/server-errors'
import { telemetry } from 'storybook/internal/telemetry';

import boxen from 'boxen';
// eslint-disable-next-line depend/ban-dependencies
import execa from 'execa';
import picocolors from 'picocolors';
import prompts from 'prompts';
Expand Down
1 change: 1 addition & 0 deletions code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"esbuild-plugin-alias": "^0.2.1",
"eslint": "^8.56.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-depend": "^0.11.0",
"eslint-plugin-local-rules": "portal:../scripts/eslint-plugin-local-rules",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-storybook": "^0.8.0",
Expand Down
19 changes: 19 additions & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6891,6 +6891,7 @@ __metadata:
esbuild-plugin-alias: "npm:^0.2.1"
eslint: "npm:^8.56.0"
eslint-import-resolver-typescript: "npm:^3.6.1"
eslint-plugin-depend: "npm:^0.11.0"
eslint-plugin-local-rules: "portal:../scripts/eslint-plugin-local-rules"
eslint-plugin-playwright: "npm:^1.6.2"
eslint-plugin-storybook: "npm:^0.8.0"
Expand Down Expand Up @@ -14336,6 +14337,17 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-depend@npm:^0.11.0":
version: 0.11.0
resolution: "eslint-plugin-depend@npm:0.11.0"
dependencies:
fd-package-json: "npm:^1.2.0"
module-replacements: "npm:^2.1.0"
semver: "npm:^7.6.3"
checksum: 10c0/64baf4d4f5d406efa1f13bda723ff0eb5fe4cee0ae8c3679fcdfccb4d7ba3a9472416fa3c54d75f1bde3e0123e55a85774662484a5b0355812f21a8968ee784a
languageName: node
linkType: hard

"eslint-plugin-eslint-comments@npm:^3.2.0":
version: 3.2.0
resolution: "eslint-plugin-eslint-comments@npm:3.2.0"
Expand Down Expand Up @@ -21040,6 +21052,13 @@ __metadata:
languageName: node
linkType: hard

"module-replacements@npm:^2.1.0":
version: 2.5.0
resolution: "module-replacements@npm:2.5.0"
checksum: 10c0/7fcbcb19151778a2f2fa70b7bffb134bb8922b2306e2a0d7b4a863467a9d6d9d5fed537763c43272e22b69dbddaf1610746b42a68b4663aa225e85f9ae9b03c8
languageName: node
linkType: hard

"mri@npm:^1.1.0, mri@npm:^1.2.0":
version: 1.2.0
resolution: "mri@npm:1.2.0"
Expand Down
10 changes: 9 additions & 1 deletion scripts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
root: true,
extends: ['@storybook/eslint-config-storybook', 'plugin:storybook/recommended'],
extends: [
//
'@storybook/eslint-config-storybook',
'plugin:storybook/recommended',
'plugin:depend/recommended'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
Expand All @@ -11,6 +16,9 @@ module.exports = {
'@typescript-eslint/consistent-type-imports': ['error', { disallowTypeAnnotations: false }],
'no-use-before-define': 'off',
'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
"depend/ban-dependencies": ["error", {
"modules": ["lodash", "chalk", "qs", "handlebars", "fs-extra"]
}]
},
overrides: [
{
Expand Down
1 change: 1 addition & 0 deletions scripts/bench/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line depend/ban-dependencies
import { ensureDir, readJSON, readdir, writeJSON } from 'fs-extra';
import { join } from 'path';
import type { Page } from 'playwright-core';
Expand Down
2 changes: 2 additions & 0 deletions scripts/build-package.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { readJSON } from 'fs-extra';
import { posix, resolve, sep } from 'path';
import picocolors from 'picocolors';
Expand Down
2 changes: 2 additions & 0 deletions scripts/check-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// without having to build dts files for all packages in the monorepo.
// It is not implemented yet for angular, svelte and vue.
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { readJSON } from 'fs-extra';
import { resolve } from 'path';
import picocolors from 'picocolors';
Expand Down
3 changes: 3 additions & 0 deletions scripts/combine-compodoc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Compodoc does not follow symlinks (it ignores them and their contents entirely)
// So, we need to run a separate compodoc process on every symlink inside the project,
// then combine the results into one large documentation.json
// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { lstat, readFile, realpath, writeFile } from 'fs-extra';
// eslint-disable-next-line depend/ban-dependencies
import { globSync } from 'glob';
import { join, resolve } from 'path';

Expand Down
3 changes: 3 additions & 0 deletions scripts/dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { danger, fail } from 'danger';

execSync('npm install lodash');

// eslint-disable-next-line depend/ban-dependencies
const flatten = require('lodash/flatten.js');
// eslint-disable-next-line depend/ban-dependencies
const intersection = require('lodash/intersection.js');
// eslint-disable-next-line depend/ban-dependencies
const isEmpty = require('lodash/isEmpty.js');

const pkg = require('../code/package.json');
Expand Down
2 changes: 2 additions & 0 deletions scripts/get-report-message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { readJson } from 'fs-extra';
import { join } from 'path';

Expand Down
1 change: 1 addition & 0 deletions scripts/get-template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { pathExists, readFile } from 'fs-extra';
import { readdir } from 'fs/promises';
import picocolors from 'picocolors';
Expand Down
1 change: 1 addition & 0 deletions scripts/knip.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join, relative } from 'node:path';

// eslint-disable-next-line depend/ban-dependencies
import fg from 'fast-glob';
import type { KnipConfig } from 'knip';
import { match } from 'minimatch';
Expand Down
1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"eslint": "^8.57.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-depend": "^0.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-file-progress": "^1.4.0",
"eslint-plugin-html": "^8.1.1",
Expand Down
2 changes: 2 additions & 0 deletions scripts/prepare/addon-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { builtinModules } from 'node:module';

import type { Metafile } from 'esbuild';
import aliasPlugin from 'esbuild-plugin-alias';
// eslint-disable-next-line depend/ban-dependencies
import * as fs from 'fs-extra';
// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import { dirname, join, parse, posix, relative, sep } from 'path';
import slash from 'slash';
Expand Down
2 changes: 2 additions & 0 deletions scripts/prepare/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { dirname, join, parse, posix, relative, resolve, sep } from 'node:path';

import type { Metafile } from 'esbuild';
import aliasPlugin from 'esbuild-plugin-alias';
// eslint-disable-next-line depend/ban-dependencies
import * as fs from 'fs-extra';
// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import slash from 'slash';
import { dedent } from 'ts-dedent';
Expand Down
1 change: 1 addition & 0 deletions scripts/prepare/check.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line depend/ban-dependencies
import fs from 'fs-extra';
import { join } from 'path';
import ts from 'typescript';
Expand Down
2 changes: 2 additions & 0 deletions scripts/prepare/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import * as process from 'node:process';
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
import { spawn } from 'cross-spawn';
import * as esbuild from 'esbuild';
// eslint-disable-next-line depend/ban-dependencies
import { readJson } from 'fs-extra';
// eslint-disable-next-line depend/ban-dependencies
import { glob } from 'glob';
import limit from 'p-limit';
import picocolors from 'picocolors';
Expand Down
2 changes: 2 additions & 0 deletions scripts/prepare/tsc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// eslint-disable-next-line depend/ban-dependencies
import { emptyDir, move, readJson } from 'fs-extra';
// eslint-disable-next-line depend/ban-dependencies
import { globSync } from 'glob';
import { join } from 'path';
import * as ts from 'typescript';
Expand Down
1 change: 1 addition & 0 deletions scripts/release/__tests__/is-pr-frozen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join } from 'node:path';

import { describe, expect, it, vi } from 'vitest';

// eslint-disable-next-line depend/ban-dependencies
import * as fsExtraImp from 'fs-extra';
import * as simpleGitImp from 'simple-git';

Expand Down
2 changes: 2 additions & 0 deletions scripts/release/__tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { join } from 'node:path';

import { describe, expect, it, vi } from 'vitest';

// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import * as fsExtraImp from 'fs-extra';

import type * as MockedFSToExtra from '../../../code/__mocks__/fs-extra';
Expand Down
1 change: 1 addition & 0 deletions scripts/release/__tests__/write-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join } from 'node:path';

import { beforeEach, describe, expect, it, vi } from 'vitest';

// eslint-disable-next-line depend/ban-dependencies
import * as fsExtraImp from 'fs-extra';
import { dedent } from 'ts-dedent';

Expand Down
1 change: 1 addition & 0 deletions scripts/release/get-changelog-from-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'node:path';

import { setOutput } from '@actions/core';
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { readFile } from 'fs-extra';
import picocolors from 'picocolors';
import semver from 'semver';
Expand Down
1 change: 1 addition & 0 deletions scripts/release/get-current-version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { join } from 'node:path';

import { setOutput } from '@actions/core';
// eslint-disable-next-line depend/ban-dependencies
import { readJson } from 'fs-extra';
import picocolors from 'picocolors';

Expand Down
1 change: 1 addition & 0 deletions scripts/release/is-pr-frozen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'node:path';

import { setOutput } from '@actions/core';
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { readJson } from 'fs-extra';
import picocolors from 'picocolors';

Expand Down
1 change: 1 addition & 0 deletions scripts/release/label-patches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import ora from 'ora';
import { v4 as uuidv4 } from 'uuid';

Expand Down
1 change: 1 addition & 0 deletions scripts/release/pick-patches.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setOutput } from '@actions/core';
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import ora from 'ora';
import picocolors from 'picocolors';
import invariant from 'tiny-invariant';
Expand Down
Loading

0 comments on commit b3d4370

Please sign in to comment.