Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-bobcats-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sumup-oss/foundry": minor
---

Removed warnings about missing or unsupported ESLint plugins to speed up linting.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ yargs(hideBin(process.argv))
)
.command(
'debug',
'See which frameworks and plugins Foundry has detected in your project',
'See which packages and plugins Foundry has detected in your project',
execute('debug'),
)
.command(
Expand Down
25 changes: 1 addition & 24 deletions src/configs/eslint/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
* limitations under the License.
*/

import { defineConfig as defineESLintConfig } from 'eslint/config';

import { readPackageJson } from '../../lib/files.js';
import {
warnAboutMissingPlugins,
warnAboutUnsupportedPlugins,
} from '../../lib/options.js';

import { browser } from './browser.js';
import { ignores } from './ignores.js';
import { javascript } from './javascript.js';
Expand All @@ -32,22 +24,7 @@ import { storybook } from './storybook.js';
import { tests } from './tests.js';
import { typescript } from './typescript.js';

/**
* Helper function to define a config array and validate that all plugins
* relevant to the project have been installed.
*
* @param args The arguments to the function.
* @returns The config array.
* @throws {TypeError} If no arguments are provided or if an argument is not an object.
*/
export const defineConfig: typeof defineESLintConfig = (...args) => {
const packageJson = readPackageJson();

warnAboutUnsupportedPlugins(packageJson);
warnAboutMissingPlugins(packageJson);

return defineESLintConfig(...args);
};
export { defineConfig } from 'eslint/config';

export const configs = {
browser,
Expand Down
11 changes: 2 additions & 9 deletions src/configs/eslint/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

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

import {
Environment,
Framework,
Language,
Plugin,
} from '../../types/shared.js';
import { Environment, Language, Plugin } from '../../types/shared.js';

import { files } from './index.js';

Expand All @@ -31,7 +26,6 @@ describe('eslint', () => {
packageType: 'commonjs',
language: Language.JavaScript,
environments: [],
frameworks: [],
plugins: [],
openSource: false,
});
Expand All @@ -43,8 +37,7 @@ describe('eslint', () => {
packageType: 'module',
language: Language.TypeScript,
environments: [Environment.Browser, Environment.Node],
frameworks: [Framework.React],
plugins: [Plugin.Jest, Plugin.Storybook],
plugins: [Plugin.React, Plugin.Jest, Plugin.Storybook],
openSource: true,
});
expect(actual).toMatchSnapshot();
Expand Down
5 changes: 2 additions & 3 deletions src/configs/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { getFileExtension } from '../../lib/files.js';
import {
Environment,
type File,
Framework,
Language,
type Options,
Plugin,
Expand Down Expand Up @@ -57,10 +56,10 @@ export function files(options: Required<Options>): File[] {
configs.push('configs.openSource');
}

if (options.frameworks.includes(Framework.Nextjs)) {
if (options.plugins?.includes(Plugin.Nextjs)) {
// TODO: Add support for Next.js' ESLint plugin?
configs.push('configs.next');
} else if (options.frameworks.includes(Framework.React)) {
} else if (options.plugins?.includes(Plugin.React)) {
imports.push("import react from 'eslint-plugin-react'");
configs.push(
"{ extends: [ react.configs.recommended, react.configs['jsx-runtime'], configs.react], plugins: { react }}",
Expand Down
29 changes: 1 addition & 28 deletions src/lib/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@

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

import { Environment, Framework, Language, Plugin } from '../types/shared.js';
import { Environment, Language, Plugin } from '../types/shared.js';

import * as logger from './logger.js';
import {
BROWSER_LIBRARIES,
detectEnvironments,
detectFrameworks,
detectLanguage,
detectOpenSource,
detectPlugins,
Expand Down Expand Up @@ -163,32 +162,6 @@ describe('options', () => {
});
});

describe('detectFrameworks', () => {
it.each([
['next', Framework.Nextjs],
['react', Framework.React],
])('should, when `%s` is installed, include the `%s` preset', (library, preset) => {
const packageJson = {
...basePackageJson,
dependencies: { [library]: '^1.0.0' },
};
const actual = detectFrameworks(packageJson);

expect(actual).toContain(preset);
});

it('should not include the `React` preset when `next` is installed', () => {
const packageJson = {
...basePackageJson,
dependencies: { next: '^1.0.0', react: '^1.0.0' },
};
const actual = detectFrameworks(packageJson);

expect(actual).toContain(Framework.Nextjs);
expect(actual).not.toContain(Framework.React);
});
});

describe('detectPlugins', () => {
it.each([
['@next/eslint-plugin-next', Plugin.Nextjs],
Expand Down
19 changes: 0 additions & 19 deletions src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { intersects } from 'semver';

import {
Environment,
Framework,
Language,
type Options,
type PackageJson,
Expand Down Expand Up @@ -122,7 +121,6 @@ export function getOptions(): Required<Options> {
packageType: packageJson.type || 'commonjs',
language: pick(config.language, detectLanguage),
environments: pick(config.environments, detectEnvironments),
frameworks: pick(config.frameworks, detectFrameworks),
// TODO: Differentiate between ESLint and Stylelint plugins
plugins: pick(config.plugins, detectPlugins),
openSource: pick(config.openSource, detectOpenSource),
Expand Down Expand Up @@ -180,23 +178,6 @@ export function detectEnvironments(packageJson: PackageJson): Environment[] {
return environments;
}

export function detectFrameworks(packageJson: PackageJson): Framework[] {
const frameworks: Framework[] = [];

if (hasDependency(packageJson, 'next')) {
frameworks.push(Framework.Nextjs);
}

if (
!hasDependency(packageJson, 'next') &&
hasDependency(packageJson, 'react')
) {
frameworks.push(Framework.React);
}

return frameworks;
}

export function warnAboutUnsupportedPlugins(packageJson: PackageJson): void {
PLUGINS.forEach(({ eslintPlugins, stylelintPlugins = {} }) => {
Object.entries({ ...eslintPlugins, ...stylelintPlugins }).forEach(
Expand Down
7 changes: 1 addition & 6 deletions src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ export enum Environment {
Browser = 'Browser',
}

export enum Framework {
React = 'React',
Nextjs = 'Next.js',
}

export enum Plugin {
CircuitUI = 'Circuit UI',
Cypress = 'Cypress',
Emotion = 'Emotion',
Jest = 'Jest',
Nextjs = 'Next.js',
Playwright = 'Playwright',
React = 'React',
Storybook = 'Storybook',
TestingLibrary = 'Testing Library',
}
Expand All @@ -49,7 +45,6 @@ export interface Options {
packageType?: ModuleType;
language?: Language;
environments?: Environment[];
frameworks?: Framework[];
plugins?: Plugin[];
openSource?: boolean;
}
Expand Down
Loading