From ed946b434efaab9e774795cc9acf32438721a3bb Mon Sep 17 00:00:00 2001 From: "@sangrepura" Date: Sat, 28 Sep 2024 07:30:28 -0500 Subject: [PATCH 1/5] docs: :memo: adds instructions for integrating official ESlint > v9.9.0 `ts` file support (#268) ESlint > v9.9.0 includes experimental support for Typescript configuration files using the flag `unstable_ts_config`. This adds documentation for adding the flag to VSCode. --- apps/docs-website/docs/vscode-support.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/docs-website/docs/vscode-support.md b/apps/docs-website/docs/vscode-support.md index ed5a6bfd..d5300649 100644 --- a/apps/docs-website/docs/vscode-support.md +++ b/apps/docs-website/docs/vscode-support.md @@ -19,6 +19,18 @@ To make the [VSCode ESLint Extension](https://marketplace.visualstudio.com/items } ``` +## Typescript support + +### Using official ESlint > v9.9.0 + +If you are using an `eslint.config.ts` with [ESLint's experimental support for Typescript based configuration files](https://github.com/eslint/eslint/releases/tag/v9.9.0), add this to your workspace's `.vscode/settings.json`: + +```JSONC title=".vscode/settings.json" +"eslint.options": { + "flags": ["unstable_ts_config"] +} +``` + ## Astro support For [Astro](https://astro.build/) projects, add the astro extension too: From 68fe1cb2ee525b6a21d2908b0bcce5a39ce2f8cd Mon Sep 17 00:00:00 2001 From: AndreaPontrandolfo Date: Wed, 13 Nov 2024 01:13:31 +0100 Subject: [PATCH 2/5] feature(cli): removed eslint-ts-patch --- apps/docs-website/docusaurus.config.ts | 2 +- packages/sheriff-create-config/src/index.ts | 8 ++++---- .../src/utils/askForEslintTsConfig.ts | 13 +++++++++++++ .../src/utils/askForEslintTsPatch.ts | 14 -------------- .../src/utils/getRequiredPackages.ts | 9 +-------- .../src/utils/setDependencies.ts | 3 +-- .../src/utils/setEslintConfig.ts | 6 +++--- 7 files changed, 23 insertions(+), 32 deletions(-) create mode 100644 packages/sheriff-create-config/src/utils/askForEslintTsConfig.ts delete mode 100644 packages/sheriff-create-config/src/utils/askForEslintTsPatch.ts diff --git a/apps/docs-website/docusaurus.config.ts b/apps/docs-website/docusaurus.config.ts index 0ac86e2a..05241f2d 100644 --- a/apps/docs-website/docusaurus.config.ts +++ b/apps/docs-website/docusaurus.config.ts @@ -22,7 +22,7 @@ const config: Config = { baseUrl: '/', future: { - experimental_faster: true, + experimental_faster: false, }, // GitHub pages deployment config. diff --git a/packages/sheriff-create-config/src/index.ts b/packages/sheriff-create-config/src/index.ts index df2a276a..2a726e73 100644 --- a/packages/sheriff-create-config/src/index.ts +++ b/packages/sheriff-create-config/src/index.ts @@ -5,7 +5,7 @@ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import packageJson from '../package.json'; import { askForCustomPath } from './utils/askForCustomPath'; -import { askForEslintTsPatch } from './utils/askForEslintTsPatch'; +import { askForEslintTsConfig } from './utils/askForEslintTsConfig'; import { askForPrettierSupport } from './utils/askForPrettierSupport'; import { setDependencies } from './utils/setDependencies'; import { setEslintConfig } from './utils/setEslintConfig'; @@ -33,15 +33,15 @@ async function main() { const hasLocalPrettierSupport = isWorkspace ? await askForPrettierSupport() : false; - const isEslintTsPatchRequired = await askForEslintTsPatch(); + const isEslintTsConfig = await askForEslintTsConfig(); - await setEslintConfig(isEslintTsPatchRequired, customProjectRootPath); + await setEslintConfig(isEslintTsConfig, customProjectRootPath); if (!isWorkspace || hasLocalPrettierSupport) { await setPrettierConfig(customProjectRootPath); await setPrettierIgnore(customProjectRootPath); } - await setDependencies(isEslintTsPatchRequired, customProjectRootPath); + await setDependencies(customProjectRootPath); consola.info("You're all set!"); } diff --git a/packages/sheriff-create-config/src/utils/askForEslintTsConfig.ts b/packages/sheriff-create-config/src/utils/askForEslintTsConfig.ts new file mode 100644 index 00000000..6d0a2074 --- /dev/null +++ b/packages/sheriff-create-config/src/utils/askForEslintTsConfig.ts @@ -0,0 +1,13 @@ +import { colors } from 'consola/utils'; +import { customConsolaPrompt } from './customConsolaPrompt'; + +export const askForEslintTsConfig = async (): Promise => { + const isEslintTsConfig = await customConsolaPrompt( + `Do you prefer the config as a Typescript file? The generated config will be a ${colors.bold('eslint.config.ts')} file`, + { + type: 'confirm', + }, + ); + + return isEslintTsConfig; +}; diff --git a/packages/sheriff-create-config/src/utils/askForEslintTsPatch.ts b/packages/sheriff-create-config/src/utils/askForEslintTsPatch.ts deleted file mode 100644 index 5fd21e96..00000000 --- a/packages/sheriff-create-config/src/utils/askForEslintTsPatch.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { colors } from 'consola/utils'; -import { customConsolaPrompt } from './customConsolaPrompt'; - -export const askForEslintTsPatch = async (): Promise => { - const isTsEslintPatchWanted = await customConsolaPrompt( - `Do you want to use the ${colors.bold('eslint-ts-patch')}?`, - { - type: 'confirm', - // onState: gracefullyAbort, - }, - ); - - return isTsEslintPatchWanted; -}; diff --git a/packages/sheriff-create-config/src/utils/getRequiredPackages.ts b/packages/sheriff-create-config/src/utils/getRequiredPackages.ts index 0dc8bfda..3e6b66af 100644 --- a/packages/sheriff-create-config/src/utils/getRequiredPackages.ts +++ b/packages/sheriff-create-config/src/utils/getRequiredPackages.ts @@ -1,8 +1,6 @@ import { consola } from 'consola'; -export const getRequiredPackages = ( - isEslintTsPatchRequired: boolean, -): string[] => { +export const getRequiredPackages = (): string[] => { const requiredPackages: string[] = []; requiredPackages.push('eslint'); @@ -14,10 +12,5 @@ export const getRequiredPackages = ( requiredPackages.push('eslint-config-sheriff'); consola.start("Installing 'eslint-config-sheriff'..."); - if (isEslintTsPatchRequired) { - requiredPackages.push(`eslint-ts-patch`, `eslint@npm:eslint-ts-patch`); - consola.start("Installing 'eslint-ts-patch'..."); - } - return requiredPackages; }; diff --git a/packages/sheriff-create-config/src/utils/setDependencies.ts b/packages/sheriff-create-config/src/utils/setDependencies.ts index 0fc8bc8e..04727b93 100644 --- a/packages/sheriff-create-config/src/utils/setDependencies.ts +++ b/packages/sheriff-create-config/src/utils/setDependencies.ts @@ -2,10 +2,9 @@ import { autoInstallPackages } from './autoInstallPackages'; import { getRequiredPackages } from './getRequiredPackages'; export const setDependencies = async ( - isEslintTsPatchRequired: boolean, customProjectRootPath: string | null, ): Promise => { - const packages = getRequiredPackages(isEslintTsPatchRequired); + const packages = getRequiredPackages(); await autoInstallPackages(packages, customProjectRootPath); }; diff --git a/packages/sheriff-create-config/src/utils/setEslintConfig.ts b/packages/sheriff-create-config/src/utils/setEslintConfig.ts index 724d4435..3b4393a8 100644 --- a/packages/sheriff-create-config/src/utils/setEslintConfig.ts +++ b/packages/sheriff-create-config/src/utils/setEslintConfig.ts @@ -7,7 +7,7 @@ import { patchedFindUp } from './patchedFindUp'; import { throwError } from './throwError'; export const setEslintConfig = async ( - isEslintTsPatchRequired: boolean, + isEslintTsConfig: boolean, customProjectRootPath: string | null, ): Promise => { const ESLINT_CONFIG_JS_FILE_NAME = 'eslint.config.js'; @@ -52,7 +52,7 @@ export const setEslintConfig = async ( consola.start( `No ESLint config files were found. Generating and configuring ${ - isEslintTsPatchRequired + isEslintTsConfig ? colors.bold(ESLINT_CONFIG_TS_FILE_NAME) : colors.bold(ESLINT_CONFIG_JS_FILE_NAME) } file...`, @@ -62,7 +62,7 @@ export const setEslintConfig = async ( 'If you have other ESLint configs in your project, remove them', ); - if (isEslintTsPatchRequired) { + if (isEslintTsConfig) { createFile( ESLINT_CONFIG_TS_FILE_NAME, await getEslintConfigRawText('ts', customProjectRootPath), From 556b2d93ccbdfc02829aec6108372e8b5494fe1a Mon Sep 17 00:00:00 2001 From: AndreaPontrandolfo Date: Wed, 13 Nov 2024 01:13:42 +0100 Subject: [PATCH 3/5] docs(website): updated docs --- apps/docs-website/docs/setup/manual-setup.mdx | 5 +---- .../docs/typescript-support/eslint-config-ts.md | 11 ++++++++--- apps/docs-website/docs/vscode-support.md | 6 ++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/docs-website/docs/setup/manual-setup.mdx b/apps/docs-website/docs/setup/manual-setup.mdx index 1ee25030..492996ac 100644 --- a/apps/docs-website/docs/setup/manual-setup.mdx +++ b/apps/docs-website/docs/setup/manual-setup.mdx @@ -70,10 +70,7 @@ Follow these steps: If you want to have a `.ts` configuration file instead of the default `.js` file, follow these steps: - - - ```bash npm2yarn - npm install -D eslint-ts-patch eslint@npm:eslint-ts-patch - ``` + - make sure your installed ESLint version is `>=9.9.0` - change the extension of `eslint.config.mjs` from `.mjs` to `.ts` - define the types of the `sheriffOptions` object: diff --git a/apps/docs-website/docs/typescript-support/eslint-config-ts.md b/apps/docs-website/docs/typescript-support/eslint-config-ts.md index e6f9f1ac..2cedb5de 100644 --- a/apps/docs-website/docs/typescript-support/eslint-config-ts.md +++ b/apps/docs-website/docs/typescript-support/eslint-config-ts.md @@ -6,9 +6,14 @@ sidebar_position: 1 The `eslint.config.ts` file is a Typescript-enabled version of the `eslint.config.js` file. -To make this feature possible, Sheriff leverage [eslint-ts-patch](https://github.com/antfu/eslint-ts-patch) under the hood.
-To learn more, consult the [official documentation of eslint-ts-patch](https://github.com/antfu/eslint-ts-patch). - If you go through the [automatic setup](../setup/automatic-setup.mdx) of Sheriff, at some point the wizard will ask you if you want to setup Sheriff with a `eslint.config.ts` file instead of the default `eslint.config.js` file. Choose `yes` if you want to have a typesafe ESLint configuration file. Instead, if you choose the manual installation, follow the instruction in the [manual setup page](../setup/manual-setup.mdx). + +Also check the specific docs for the [VSCode integration](../vscode-support.md#eslintconfigts-support). + +:::warning + +This feature is available only with ESLint version `>=9.9.0`. + +::: diff --git a/apps/docs-website/docs/vscode-support.md b/apps/docs-website/docs/vscode-support.md index d5300649..6c2a5405 100644 --- a/apps/docs-website/docs/vscode-support.md +++ b/apps/docs-website/docs/vscode-support.md @@ -19,11 +19,9 @@ To make the [VSCode ESLint Extension](https://marketplace.visualstudio.com/items } ``` -## Typescript support +## `eslint.config.ts` support -### Using official ESlint > v9.9.0 - -If you are using an `eslint.config.ts` with [ESLint's experimental support for Typescript based configuration files](https://github.com/eslint/eslint/releases/tag/v9.9.0), add this to your workspace's `.vscode/settings.json`: +If you are using the `eslint.config.ts` config, add this to your `.vscode/settings.json`: ```JSONC title=".vscode/settings.json" "eslint.options": { From 9556270957eabe17f2bf90de504ccef1bd2bd0c8 Mon Sep 17 00:00:00 2001 From: AndreaPontrandolfo Date: Wed, 13 Nov 2024 01:15:05 +0100 Subject: [PATCH 4/5] added changeset --- .changeset/small-rivers-pump.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/small-rivers-pump.md diff --git a/.changeset/small-rivers-pump.md b/.changeset/small-rivers-pump.md new file mode 100644 index 00000000..ec05d07e --- /dev/null +++ b/.changeset/small-rivers-pump.md @@ -0,0 +1,7 @@ +--- +'@sherifforg/create-config': minor +--- + +feature(cli): removed eslint-ts-patch +Fixes [#201](https://github.com/AndreaPontrandolfo/sheriff/issues/201) +Fixes [#268](https://github.com/AndreaPontrandolfo/sheriff/issues/268) From f4d9b8a09e00b183b8b6115c90d5b83fc8acf357 Mon Sep 17 00:00:00 2001 From: AndreaPontrandolfo Date: Wed, 13 Nov 2024 01:21:45 +0100 Subject: [PATCH 5/5] added permissions for token --- .github/workflows/release.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68a7b2f5..5cca58b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,10 @@ on: concurrency: ${{ github.workflow }}-${{ github.ref }} +permissions: + contents: write + id-token: write + jobs: release: name: Release