Skip to content

Commit 4b97dee

Browse files
TkDodoandrewshie-sentry
authored andcommitted
ref(✂️): enable knip in CI (#92010)
This PR: - gets violations for `yarn run knip` to zero. - enables `knip` in CI. Sorry for this being a larger PR, but I fear that by the time I’ve broken it down and all the individuals get merged, there will be now things that need removal. It should be the last one, as `knip` is then a mandatory CI check 🎉 Note: The `knip --prod` run is not yet enabled, as I’m waiting for some replay specific feedback about 3 more things that need to be removed. This is going to be a small follow-up.
1 parent c7a6cc4 commit 4b97dee

File tree

56 files changed

+220
-1795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+220
-1795
lines changed

.github/workflows/frontend.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ jobs:
107107
id: eslint
108108
run: yarn run lint:js
109109

110+
knip:
111+
if: needs.files-changed.outputs.frontend_all == 'true'
112+
needs: files-changed
113+
name: knip
114+
runs-on: ubuntu-24.04
115+
steps:
116+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
117+
118+
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4
119+
id: setup-node
120+
with:
121+
node-version-file: '.volta.json'
122+
123+
- name: node_modules cache
124+
uses: actions/cache@v4.2.0
125+
id: nodemodulescache
126+
with:
127+
path: node_modules
128+
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock', 'api-docs/yarn.lock', '.volta.json') }}
129+
130+
- name: Install Javascript Dependencies
131+
if: steps.nodemodulescache.outputs.cache-hit != 'true'
132+
run: yarn install --frozen-lockfile
133+
134+
# Setup custom eslint matcher, see https://github.com/actions/setup-node/issues/97
135+
- name: setup matchers
136+
run: |
137+
echo "::remove-matcher owner=masters::"
138+
echo "::add-matcher::.github/eslint-stylish.json"
139+
140+
- name: knip
141+
id: knip
142+
run: yarn run knip
143+
144+
- name: knip-prod
145+
id: knip-prod
146+
run: yarn run knip:prod
147+
110148
frontend-jest-tests:
111149
if: needs.files-changed.outputs.testable_rules_changed == 'true' || needs.files-changed.outputs.testable_modified == 'true'
112150
needs: [files-changed]
@@ -184,7 +222,7 @@ jobs:
184222
# It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
185223
# This check is the only required Github check
186224
frontend-required-check:
187-
needs: [files-changed, frontend-jest-tests, typescript, eslint]
225+
needs: [files-changed, frontend-jest-tests, typescript, eslint, knip]
188226
name: Frontend
189227
# This is necessary since a failed/skipped dependent job would cause this job to be skipped
190228
if: always()

knip.config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {compile} from '@mdx-js/mdx';
12
import type {KnipConfig} from 'knip';
23

34
const productionEntryPoints = [
@@ -34,6 +35,8 @@ const storyBookEntryPoints = [
3435
'static/app/stories/storyBook.tsx',
3536
// custom webpack loaders for stories
3637
'static/app/stories/*loader.ts',
38+
// we have some stories in mdx format
39+
'static/app/**/*.mdx',
3740
];
3841

3942
const config: KnipConfig = {
@@ -45,6 +48,7 @@ const config: KnipConfig = {
4548
storybook: true,
4649
project: [
4750
'static/**/*.{js,mjs,ts,tsx}!',
51+
'static/app/**/*.mdx',
4852
'tests/js/**/*.{js,mjs,ts,tsx}',
4953
// exclude this directory because it's how you set up mocks in jest (https://jestjs.io/docs/manual-mocks)
5054
'!static/{app,gsApp}/**/__mocks__/**',
@@ -54,8 +58,19 @@ const config: KnipConfig = {
5458
'!static/**/*{t,T}estUtils*.{js,mjs,ts,tsx}!',
5559
// helper files for stories - it's fine that they are only used in tests
5660
'!static/app/**/__stories__/*.{js,mjs,ts,tsx}!',
57-
'!static/app/{components,views}/stories/*.{js,mjs,ts,tsx}!',
61+
'!static/app/stories/*.{js,mjs,ts,tsx}!',
5862
],
63+
compilers: {
64+
mdx: async text => {
65+
const result = await compile(text, {
66+
providerImportSource: '@mdx-js/react',
67+
jsx: true,
68+
outputFormat: 'program',
69+
});
70+
71+
return String(result);
72+
},
73+
},
5974
rules: {
6075
binaries: 'off',
6176
dependencies: 'off',

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
"@eslint/eslintrc": "^3.3.0",
183183
"@eslint/js": "^9.22.0",
184184
"@mdx-js/loader": "^3.1.0",
185+
"@mdx-js/mdx": "^3.1.0",
185186
"@pmmmwh/react-refresh-webpack-plugin": "0.5.16",
186187
"@sentry/jest-environment": "6.0.0",
187188
"@sentry/profiling-node": "9.16.1",
@@ -217,7 +218,7 @@
217218
"jest-environment-jsdom": "29.7.0",
218219
"jest-fail-on-console": "3.3.0",
219220
"jest-junit": "16.0.0",
220-
"knip": "^5.55.1",
221+
"knip": "^5.57.0",
221222
"postcss-styled-syntax": "0.7.0",
222223
"react-refresh": "0.16.0",
223224
"stylelint": "16.10.0",

static/app/actionCreators/guides.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ export function setForceHide(forceHide: boolean) {
4646
GuideStore.setForceHide(forceHide);
4747
}
4848

49-
export function toStep(step: number) {
50-
GuideStore.toStep(step);
51-
}
52-
5349
export function closeGuide(dismissed?: boolean) {
5450
GuideStore.closeGuide(dismissed);
5551
}
@@ -89,7 +85,7 @@ export function recordFinish(guide: string, orgId: string | null) {
8985
});
9086
}
9187

92-
export function recordDismiss(guide: string, step: number, orgId: string | null) {
88+
function recordDismiss(guide: string, step: number, orgId: string | null) {
9389
if (!isDemoModeActive()) {
9490
api.requestPromise('/assistant/', {
9591
method: 'PUT',

static/app/api.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ function buildRequestUrl(baseUrl: string, path: string, options: RequestOptions)
217217
/**
218218
* Check if the API response says project has been renamed. If so, redirect
219219
* user to new project slug
220+
* @public used in __mocks__/api.tsx with jest.requireActual
220221
*/
221222
// TODO(ts): refine this type later
222223
export function hasProjectBeenRenamed(response: ResponseMeta) {

static/app/components/charts/treeCoverageSunburstChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function bfsFilter(root: ProcessedTreeCoverageSunburstData, maxDepth: number) {
5252
* children: <recursive structure>[] | undefined - only dir nodes should have the children field;
5353
* }
5454
*/
55-
export interface TreeCoverageSunburstData {
55+
interface TreeCoverageSunburstData {
5656
children: TreeCoverageSunburstData[];
5757
coverage: number;
5858
fullPath: string;

static/app/components/events/autofix/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ type AutofixRelevantCodeFile = {
176176
repo_name: string;
177177
};
178178

179-
export type AutofixRelevantCodeFileWithUrl = AutofixRelevantCodeFile & {
179+
type AutofixRelevantCodeFileWithUrl = AutofixRelevantCodeFile & {
180180
url?: string;
181181
};
182182

static/app/components/issues/compactIssue.tsx

Lines changed: 0 additions & 206 deletions
This file was deleted.

static/app/components/performance/spanSearchQueryBuilder.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export function SpanSearchQueryBuilder(props: SpanSearchQueryBuilderProps) {
167167
return <IndexedSpanSearchQueryBuilder {...props} />;
168168
}
169169

170-
export function IndexedSpanSearchQueryBuilder({
170+
function IndexedSpanSearchQueryBuilder({
171171
initialQuery,
172172
searchSource,
173173
datetime,
@@ -189,7 +189,7 @@ export function IndexedSpanSearchQueryBuilder({
189189
return <SearchQueryBuilder {...searchQueryBuilderProps} />;
190190
}
191191

192-
export function EapSpanSearchQueryBuilder({
192+
function EapSpanSearchQueryBuilder({
193193
initialQuery,
194194
searchSource,
195195
datetime,

0 commit comments

Comments
 (0)