Skip to content

chore: lint and typecheck top level #8880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5be3fa1
lint and typecheck top level
abrahamguo Apr 7, 2024
6ac4c2d
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Apr 7, 2024
57bed67
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Apr 10, 2024
642c869
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo May 28, 2024
04e4774
move to repo-tools
abrahamguo May 29, 2024
57f7ab2
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo May 29, 2024
a26356b
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo May 30, 2024
73bdac9
move breaking-pr-check to ts
abrahamguo May 31, 2024
72fd63d
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo May 31, 2024
a4f3f90
fix file extension
abrahamguo May 31, 2024
b4b5af6
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jun 3, 2024
375001f
convert pipeline to tsx
abrahamguo Jun 3, 2024
6cbd506
revert unnecessary built
abrahamguo Jun 3, 2024
37a51ec
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jun 3, 2024
47326d0
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jun 3, 2024
a918669
move more stuff inside repo-tools
abrahamguo Jun 3, 2024
08f7d27
update paths
abrahamguo Jun 3, 2024
c34477b
include knip in TSConfig
abrahamguo Jun 3, 2024
da1a40d
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jun 14, 2024
956d1c2
add to cspell
abrahamguo Jun 14, 2024
7648cb8
remove exaca
abrahamguo Jun 14, 2024
2d6252b
add script
abrahamguo Jun 14, 2024
c631a86
one fewer knip error
abrahamguo Jun 17, 2024
ea6d4b0
fix TS error
abrahamguo Jun 17, 2024
9504db2
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jun 17, 2024
b65577e
add import attribute
abrahamguo Jun 18, 2024
9d6601c
lint
abrahamguo Jun 18, 2024
7a86edf
suppress
abrahamguo Jun 18, 2024
b5599b8
add to package.json
abrahamguo Jun 18, 2024
6bbab91
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jul 3, 2024
578af91
Merge branch 'main' into lint-top-level
JamesHenry Jul 3, 2024
960f421
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jul 16, 2024
1fb5ea7
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jul 16, 2024
e323ad0
add suppression
abrahamguo Jul 16, 2024
ec884d6
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into l…
abrahamguo Jul 21, 2024
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"destructures",
"discoverability",
"dprint",
"dummypkg",
"errored",
"erroring",
"ESLint",
Expand Down
7 changes: 5 additions & 2 deletions .github/actions/breaking-pr-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ name: Validate Breaking Change PR
description: Validate breaking change PR title and description

runs:
using: node20
main: index.js
using: 'composite'
steps:
- shell: bash
run: yarn breaking-pr-check-action
working-directory: packages/repo-tools
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.

4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default tseslint.config(
{
// note - intentionally uses computed syntax to make it easy to sort the keys
plugins: {
/* eslint-disable no-useless-computed-key */
['@typescript-eslint']: tseslint.plugin,
['@typescript-eslint/internal']: tseslintInternalPlugin,
['deprecation']: deprecationPlugin,
Expand All @@ -40,6 +41,7 @@ export default tseslint.config(
['react']: reactPlugin,
['simple-import-sort']: simpleImportSortPlugin,
['unicorn']: unicornPlugin,
/* eslint-enable no-useless-computed-key */
},
},
{
Expand All @@ -53,6 +55,8 @@ export default tseslint.config(
'**/__snapshots__/**',
'**/.docusaurus/**',
'**/build/**',
'.nx/cache',
'.yarn/*',
// Files copied as part of the build
'packages/types/src/generated/**/*.ts',
// Playground types downloaded from the web
Expand Down
7 changes: 4 additions & 3 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 Down Expand Up @@ -31,9 +31,10 @@ export default {
// imported in eslint.config.js
'@typescript-eslint/utils',
],
entry: ['tools/release/changelog-renderer.js'],
entry: ['packages/repo-tools/src/release/changelog-renderer.js'],
ignoreBinaries: [
// https://github.com/webpro/knip/issues/433
'breaking-pr-check-action',
'stylelint',
],
},
Expand All @@ -58,6 +59,7 @@ export default {
'packages/parser': {
ignore: ['tests/fixtures/**'],
},
'packages/repo-tools/src/dummypkg': {},
'packages/scope-manager': {
ignore: ['tests/fixtures/**'],
},
Expand Down Expand Up @@ -120,6 +122,5 @@ export default {
'src/mock/util.js',
],
},
'tools/dummypkg': {},
},
} satisfies KnipConfig;
4 changes: 2 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"changelog": {
"workspaceChangelog": {
"createRelease": "github",
"renderer": "{workspaceRoot}/tools/release/changelog-renderer"
"renderer": "{workspaceRoot}/packages/repo-tools/src/release/changelog-renderer"
},
"projectChangelogs": {
"renderer": "{workspaceRoot}/tools/release/changelog-renderer"
"renderer": "{workspaceRoot}/packages/repo-tools/src/release/changelog-renderer"
}
},
"version": {
Expand Down
20 changes: 7 additions & 13 deletions package.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of adding in "secondary" code paths, like having two ways of running linting or type checking &&d together. It'd be less code & complexity to get the "primary" (npx nx ...) commands working as expected.

Let's fine a way to include what's under .github/ and tools/ under nx. packages/repo-tools now exists, maybe that's a good place for some files?

Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@
"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",
"lint": "npx nx lint eslint-plugin --skip-nx-cache && npx nx run-many --target=lint --parallel --exclude eslint-plugin && eslint . --ignore-pattern=packages --cache",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still does the && strategy 😕. Surely there's got to be a way in Nx to set up a project to include root-level files, so the npx nx run-many --target=lint run would include them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I can look into that

"postinstall": "npx nx run repo-tools:postinstall-script",
"pre-commit": "yarn lint-staged",
"release": "tsx tools/release/release.mts",
"release": "tsx packages/repo-tools/src/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-integration": "npx nx run integration-tests:test",
"typecheck": "npx nx run-many --target=typecheck --parallel"
"typecheck": "npx nx run-many --target=typecheck --parallel && tsc"
},
"engines": {
"node": "^18.18.0 || >=20.0.0"
},
"devDependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@babel/code-frame": "^7.24.2",
"@babel/core": "^7.24.4",
"@babel/eslint-parser": "^7.24.1",
Expand All @@ -79,7 +77,6 @@
"@types/node": "^20.12.5",
"@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin-internal": "workspace:^",
"console-fail-test": "^0.2.3",
"cross-fetch": "^4.0.0",
Expand All @@ -97,7 +94,6 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unicorn": "^50.0.1",
"execa": "7.2.0",
"glob": "^10.3.12",
"globals": "^15.0.0",
"husky": "^9.0.0",
Expand All @@ -108,25 +104,23 @@
"make-dir": "^4.0.0",
"markdownlint-cli": "^0.41.0",
"ncp": "^2.0.0",
"netlify": "^13.1.14",
"nx": "19.4.0",
"prettier": "3.3.2",
"pretty-format": "^29.7.0",
"rimraf": "^5.0.5",
"tmp": "^0.2.1",
"tsx": "*",
"typescript": ">=4.7.4 <5.6.0",
"typescript-eslint": "workspace:^",
"yargs": "17.7.2"
"typescript-eslint": "workspace:^"
},
"resolutions": {
"@jest/create-cache-key-function": "^29",
"@jest/reporters": "^29",
"@jest/test-result": "^29",
"@microsoft/api-extractor@^7.38.0": "patch:@microsoft/api-extractor@npm%3A7.38.0#./.yarn/patches/@microsoft-api-extractor-npm-7.38.0-955f1e0725.patch",
"@types/eslint-scope": "link:./tools/dummypkg",
"@types/eslint": "link:./tools/dummypkg",
"@types/estree": "link:./tools/dummypkg",
"@types/eslint-scope": "link:./packages/repo-tools/src/dummypkg",
"@types/eslint": "link:./packages/repo-tools/src/dummypkg",
"@types/estree": "link:./packages/repo-tools/src/dummypkg",
"@types/node": "^20.0.0",
"@types/react": "^18.2.14",
"eslint": "8.57.0",
Expand Down
8 changes: 7 additions & 1 deletion packages/repo-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"//": "NOTE: intentionally no build step in this package",
"scripts": {
"apply-canary-version": "npx tsx ./src/apply-canary-version.mts",
"breaking-pr-check-action": "npx tsx ./src/breaking-pr-check-action.mts",
"format": "npx prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
"generate-configs": "npx tsx ./src/generate-configs.mts",
"generate-contributors": "npx tsx ./src/generate-contributors.mts",
Expand All @@ -16,18 +17,23 @@
"typecheck": "npx tsc --noEmit"
},
"devDependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@jest/types": "29.6.3",
"@nx/devkit": "*",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "7.16.1",
"@typescript-eslint/scope-manager": "7.16.1",
"@typescript-eslint/types": "7.16.1",
"@typescript-eslint/typescript-estree": "7.16.1",
"@typescript-eslint/utils": "7.16.1",
"cross-fetch": "*",
"execa": "*",
"nx": "19.4.0",
"prettier": "^3.2.5",
"rimraf": "*",
"semver": "7.6.2",
"typescript": "*"
"typescript": "*",
"yargs": "^17.7.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const core = require('@actions/core');
const github = require('@actions/github');
import core from '@actions/core';
import github from '@actions/github';

function raiseError(message) {
function raiseError(message: string): never {
throw new Error(message);
}

async function getPullRequest() {
const client = github.getOctokit(process.env.GITHUB_TOKEN);
async function getPullRequest(): Promise<typeof data> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const client = github.getOctokit(process.env.GITHUB_TOKEN!);

const pr = github.context.payload.pull_request;
if (!pr) {
Expand All @@ -15,8 +16,9 @@ async function getPullRequest() {
);
}

const owner = pr.base.user.login;
const repo = pr.base.repo.name;
const base = pr.base as { user: { login: string }; repo: { name: string } };
const owner = base.user.login;
const repo = base.repo.name;

const { data } = await client.rest.pulls.get({
owner,
Expand All @@ -27,21 +29,24 @@ async function getPullRequest() {
return data;
}

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

function checkDescription(body, labels) {
function checkDescription(
body: string,
labels: (typeof pullRequest)['labels'],
): void {
if (!labels.some(label => label.name === 'breaking change')) {
return;
}
const [firstLine, secondLine] = body.split(/\r?\n/);

if (!firstLine || !/^BREAKING CHANGE:/.test(firstLine)) {
if (!firstLine.startsWith('BREAKING CHANGE:')) {
raiseError(
`Breaking change PR body should start with "BREAKING CHANGE:". See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
Expand All @@ -53,14 +58,10 @@ function checkDescription(body, labels) {
}
}

async function run() {
const pullRequest = await getPullRequest();
try {
checkTitle(pullRequest.title);
checkDescription(pullRequest.body, pullRequest.labels);
} catch (e) {
core.setFailed(e.message);
}
const pullRequest = await getPullRequest();
try {
checkTitle(pullRequest.title);
checkDescription(pullRequest.body ?? '', pullRequest.labels);
} catch (e) {
core.setFailed((e as Error).message);
}

run();
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading