Skip to content

Commit

Permalink
chore: reorg repo level utils, lint and typecheck repo files (#9618)
Browse files Browse the repository at this point in the history
Co-authored-by: Abraham Guo <aguo@precisionplanting.com>
  • Loading branch information
JamesHenry and abrahamguo authored Jul 28, 2024
1 parent 9fb79b4 commit 6b92aa5
Show file tree
Hide file tree
Showing 131 changed files with 380 additions and 1,252 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"destructures",
"discoverability",
"dprint",
"dummypkg",
"errored",
"erroring",
"ESLint",
Expand Down
32 changes: 22 additions & 10 deletions .github/actions/breaking-pr-check/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// @ts-check
/* eslint-disable jsdoc/no-types */

const core = require('@actions/core');
const github = require('@actions/github');

function raiseError(message) {
throw new Error(message);
}

async function getPullRequest() {
const client = github.getOctokit(process.env.GITHUB_TOKEN);
const token = process.env.GITHUB_TOKEN;
if (!token) {
throw new Error(
'The GITHUB_TOKEN environment variable is required to run this action.',
);
}
const client = github.getOctokit(token);

const pr = github.context.payload.pull_request;
if (!pr) {
Expand All @@ -27,27 +32,34 @@ async function getPullRequest() {
return data;
}

/**
* @param {string} title The PR title to check
*/
function checkTitle(title) {
if (/^[a-z]+(\([a-z-]+\))?!: /.test(title)) {
raiseError(
throw new Error(
`Do not use exclamation mark ('!') to indicate breaking change in the PR Title.`,
);
}
}

/**
* @param {string} body The body of the PR
* @param {any[]} labels The labels applied to the PR
*/
function checkDescription(body, labels) {
if (!labels.some(label => label.name === 'breaking change')) {
return;
}
const [firstLine, secondLine] = body.split(/\r?\n/);

if (!firstLine || !/^BREAKING CHANGE:/.test(firstLine)) {
raiseError(
throw new Error(
`Breaking change PR body should start with "BREAKING CHANGE:". See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
}
if (!secondLine) {
raiseError(
throw new Error(
`The description of breaking change is missing. See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
}
Expand All @@ -57,8 +69,8 @@ async function run() {
const pullRequest = await getPullRequest();
try {
checkTitle(pullRequest.title);
checkDescription(pullRequest.body, pullRequest.labels);
} catch (e) {
checkDescription(pullRequest.body ?? '', pullRequest.labels);
} catch (/** @type {any} */ e) {
core.setFailed(e.message);
}
}
Expand Down
15 changes: 0 additions & 15 deletions .github/actions/wait-for-netlify/action.yml

This file was deleted.

108 changes: 0 additions & 108 deletions .github/actions/wait-for-netlify/index.js

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ jobs:
'eslint-plugin',
'eslint-plugin-internal',
'parser',
'repo-tools',
'rule-schema-to-typescript-types',
'scope-manager',
'type-utils',
Expand Down Expand Up @@ -292,7 +291,7 @@ jobs:
uses: ./.github/actions/prepare-build

- name: Figure out and apply the next canary version
run: npx nx run repo-tools:apply-canary-version
run: npx tsx tools/release/apply-canary-version.mts

- name: Publish all packages to npm with the canary tag
# NOTE: this needs to be npx, rather than yarn, to make sure the authenticated npm registry is used
Expand Down Expand Up @@ -325,7 +324,7 @@ jobs:
uses: ./.github/actions/prepare-build

- name: Figure out and apply the next canary version
run: OVERRIDE_MAJOR_VERSION=8 npx nx run repo-tools:apply-canary-version
run: OVERRIDE_MAJOR_VERSION=8 npx tsx tools/release/apply-canary-version.mts

- name: Publish all packages to npm with the canary tag
# NOTE: this needs to be npx, rather than yarn, to make sure the authenticated npm registry is used
Expand Down
5 changes: 4 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default tseslint.config(
// register all of the plugins up-front
{
// note - intentionally uses computed syntax to make it easy to sort the keys
/* eslint-disable no-useless-computed-key */
plugins: {
['@typescript-eslint']: tseslint.plugin,
['@typescript-eslint/internal']: tseslintInternalPlugin,
Expand All @@ -41,6 +42,7 @@ export default tseslint.config(
['simple-import-sort']: simpleImportSortPlugin,
['unicorn']: unicornPlugin,
},
/* eslint-enable no-useless-computed-key */
},
{
// config with just ignores is the replacement for `.eslintignore`
Expand All @@ -53,6 +55,8 @@ export default tseslint.config(
'**/__snapshots__/**',
'**/.docusaurus/**',
'**/build/**',
'.nx/*',
'.yarn/*',
// Files copied as part of the build
'packages/types/src/generated/**/*.ts',
// Playground types downloaded from the web
Expand Down Expand Up @@ -404,7 +408,6 @@ export default tseslint.config(
files: [
'**/tools/**/*.{ts,tsx,cts,mts}',
'**/tests/**/*.{ts,tsx,cts,mts}',
'packages/repo-tools/**/*.{ts,tsx,cts,mts}',
'packages/integration-tests/**/*.{ts,tsx,cts,mts}',
],
rules: {
Expand Down
8 changes: 2 additions & 6 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { KnipConfig } from 'knip';
import type { KnipConfig } from 'knip' with { 'resolution-mode': 'import' };

export default {
rules: {
Expand All @@ -20,18 +20,14 @@ export default {
'@babel/parser',
'@babel/types',
'@nx/workspace',
'cross-fetch',
'glob',
'husky',
'jest-specific-snapshot',
'make-dir',
'ncp',
'tmp',

// imported in eslint.config.js
'@typescript-eslint/utils',
],
entry: ['tools/release/changelog-renderer.js'],
entry: ['tools/release/changelog-renderer.js', 'tools/scripts/**/*.mts'],
ignoreBinaries: [
// https://github.com/webpro/knip/issues/433
'stylelint',
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"nxCloudAccessToken": "YjIzMmMxMWItMjhiMS00NWY2LTk1NWYtYWU3YWQ0YjE4YjBlfHJlYWQ=",
"release": {
"projects": ["*"],
"projects": ["*", "!repo"],
"changelog": {
"workspaceChangelog": {
"createRelease": "github",
Expand Down
43 changes: 25 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@
},
"homepage": "https://typescript-eslint.io",
"scripts": {
"build": "npx nx run-many --target=build --parallel --exclude website --exclude website-eslint",
"build": "npx nx run-many --target=build --exclude website --exclude website-eslint",
"check-clean-workspace-after-install": "git diff --quiet --exit-code",
"check-format": "prettier --check .",
"check-spelling": "cspell --config=.cspell.json \"**/*.{md,mdx,ts,mts,cts,js,cjs,mjs,tsx,jsx}\" --no-progress --show-context --show-suggestions",
"clean": "nx run-many --target=clean",
"format": "prettier --write .",
"generate-breaking-changes": "npx nx run eslint-plugin:generate-breaking-changes",
"generate-configs": "npx nx run repo-tools:generate-configs",
"generate-contributors": "npx nx run repo-tools:generate-contributors",
"generate-sponsors": "npx nx run repo-tools:generate-sponsors",
"generate-configs": "nx generate-configs",
"generate-contributors": "nx generate-contributors",
"generate-lib": "nx generate-lib",
"generate-sponsors": "nx generate-sponsors",
"generate-website-dts": "npx nx run website:generate-website-dts",
"generate-lib": "npx nx run repo-tools:generate-lib",
"lint-fix": "yarn lint --fix",
"lint-markdown-fix": "yarn lint-markdown --fix",
"lint-markdown": "markdownlint \"**/*.md\" --config=.markdownlint.json --ignore-path=.markdownlintignore",
"lint-stylelint": "npx nx lint website stylelint",
"lint": "npx nx lint eslint-plugin --skip-nx-cache && npx nx run-many --target=lint --parallel --exclude eslint-plugin",
"postinstall": "npx nx run repo-tools:postinstall-script",
"lint": "npx nx lint eslint-plugin --skip-nx-cache && npx nx run-many --target=lint --exclude eslint-plugin",
"postinstall": "tsx tools/scripts/postinstall.mts",
"pre-commit": "yarn lint-staged",
"release": "tsx tools/release/release.mts",
"start": "npx nx run website:start",
"test": "npx nx run-many --target=test --parallel --exclude integration-tests --exclude website --exclude website-eslint",
"test": "npx nx run-many --target=test --exclude integration-tests --exclude website --exclude website-eslint",
"test-integration": "npx nx run integration-tests:test",
"typecheck": "npx nx run-many --target=typecheck --parallel"
"typecheck": "nx run-many --target=typecheck"
},
"engines": {
"node": "^18.18.0 || >=20.0.0"
Expand All @@ -63,9 +63,10 @@
"@eslint/eslintrc": "^2.1.4",
"@eslint/js": "^8.57.0",
"@jest/types": "29.6.3",
"@nx/eslint": "19.4.0",
"@nx/jest": "19.4.0",
"@nx/workspace": "19.4.0",
"@nx/devkit": "19.5.2",
"@nx/eslint": "19.5.2",
"@nx/jest": "19.5.2",
"@nx/workspace": "19.5.2",
"@swc/core": "^1.4.12",
"@swc/jest": "^0.2.36",
"@types/babel__code-frame": "^7.0.6",
Expand All @@ -80,7 +81,12 @@
"@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "workspace:^",
"@typescript-eslint/eslint-plugin-internal": "workspace:^",
"@typescript-eslint/scope-manager": "workspace:^",
"@typescript-eslint/types": "workspace:^",
"@typescript-eslint/typescript-estree": "workspace:^",
"@typescript-eslint/utils": "workspace:^",
"console-fail-test": "^0.2.3",
"cross-fetch": "^4.0.0",
"cspell": "^8.6.1",
Expand Down Expand Up @@ -108,11 +114,11 @@
"make-dir": "^4.0.0",
"markdownlint-cli": "^0.41.0",
"ncp": "^2.0.0",
"netlify": "^13.1.14",
"nx": "19.4.0",
"nx": "19.5.2",
"prettier": "3.3.2",
"pretty-format": "^29.7.0",
"rimraf": "^5.0.5",
"semver": "7.6.2",
"tmp": "^0.2.1",
"tsx": "*",
"typescript": ">=4.7.4 <5.6.0",
Expand All @@ -139,9 +145,10 @@
"tmp": "0.2.1",
"tsx": "^4.7.2",
"typescript": "5.5.2",
"eslint-plugin-eslint-plugin@^5.5.0": "patch:eslint-plugin-eslint-plugin@npm%3A5.5.1#./.yarn/patches/eslint-plugin-eslint-plugin-npm-5.5.1-4206c2506d.patch",
"@nx/eslint@19.3.0-canary.20240611-1600875": "patch:@nx/eslint@npm%3A19.3.0-canary.20240611-1600875#./.yarn/patches/@nx-eslint-npm-19.3.0-canary.20240611-1600875-f5cb695794.patch",
"nx@19.3.0-canary.20240611-1600875": "patch:nx@npm%3A19.3.0-canary.20240611-1600875#./.yarn/patches/nx-npm-19.3.0-canary.20240611-1600875-bd96520563.patch"
"eslint-plugin-eslint-plugin@^5.5.0": "patch:eslint-plugin-eslint-plugin@npm%3A5.5.1#./.yarn/patches/eslint-plugin-eslint-plugin-npm-5.5.1-4206c2506d.patch"
},
"packageManager": "yarn@3.8.2"
"packageManager": "yarn@3.8.2",
"nx": {
"includedScripts": []
}
}
Loading

0 comments on commit 6b92aa5

Please sign in to comment.