Skip to content

Commit 4c432cd

Browse files
authored
Use Knip for detecting dead code (#3426)
1 parent 0b07cb3 commit 4c432cd

Some content is hidden

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

46 files changed

+449
-370
lines changed

web-app/knip.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { KnipConfig } from "knip";
2+
3+
export default {
4+
entry: ["src/**/{index,main}.{ts,tsx}", "e2e/**/*.ts", "test/**/*.ts"],
5+
project: [
6+
"src/**/*.{ts,tsx}",
7+
"!src/api/**/*",
8+
"e2e/**/*.{ts,tsx}",
9+
"test/**/*.ts",
10+
],
11+
rules: {
12+
binaries: "error",
13+
classMembers: "error",
14+
dependencies: "error",
15+
devDependencies: "off",
16+
duplicates: "error",
17+
files: "error",
18+
nsExports: "error",
19+
nsTypes: "error",
20+
unlisted: "error",
21+
unresolved: "error",
22+
types: "error",
23+
exports: "error",
24+
enumMembers: "off",
25+
},
26+
} satisfies KnipConfig;

web-app/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"private": true,
77
"dependencies": {
88
"@reduxjs/toolkit": "^1.9.7",
9+
"clsx": "^2.1.1",
10+
"http-status-codes": "^2.3.0",
911
"kbar": "^0.1.0-beta.45",
1012
"local-storage-fallback": "^4.1.2",
1113
"lodash": "^4.17.21",
@@ -36,7 +38,8 @@
3638
"test": "react-scripts test",
3739
"eject": "react-scripts eject",
3840
"playwright": "PORT=5005 USE_BABEL_PLUGIN_ISTANBUL=1 react-app-rewired start",
39-
"find-deadcode": "ts-prune -s consoleApi.ts | sh -c '(! grep -v \"used in module\")'"
41+
"find-deadcode": "knip",
42+
"format": "prettier . --write --log-level warn"
4043
},
4144
"eslintConfig": {
4245
"extends": "react-app",
@@ -60,6 +63,7 @@
6063
"devDependencies": {
6164
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
6265
"@playwright/test": "^1.45.2",
66+
"@types/jest": "^29.5.12",
6367
"@types/lodash": "^4.17.7",
6468
"@types/luxon": "^3.4.2",
6569
"@types/node": "20.14.11",
@@ -75,14 +79,14 @@
7579
"@types/webpack-env": "^1.18.5",
7680
"babel-plugin-istanbul": "^6.1.1",
7781
"customize-cra": "^1.0.0",
82+
"knip": "^5.27.2",
7883
"minio": "^8.0.1",
7984
"nyc": "^15.1.0",
8085
"prettier": "3.3.3",
8186
"react-app-rewire-hot-loader": "^2.0.1",
8287
"react-app-rewired": "^2.2.1",
8388
"react-scripts": "5.0.1",
8489
"testcafe": "3.6.2",
85-
"ts-prune": "^0.10.3",
8690
"typescript": "^5.5.3"
8791
},
8892
"resolutions": {

web-app/src/common/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface IBytesCalc {
4141
unit: string;
4242
}
4343

44-
export interface IEmbeddedCustomButton {
44+
interface IEmbeddedCustomButton {
4545
backgroundColor: string;
4646
textColor: string;
4747
hoverColor: string;
@@ -52,7 +52,7 @@ export interface IEmbeddedCustomButton {
5252
disabledText: string;
5353
}
5454

55-
export interface IEmbeddedCustomTable {
55+
interface IEmbeddedCustomTable {
5656
border: string;
5757
disabledBorder: string;
5858
disabledBG: string;
@@ -61,14 +61,14 @@ export interface IEmbeddedCustomTable {
6161
hoverColor: string;
6262
}
6363

64-
export interface IEmbeddedInputBox {
64+
interface IEmbeddedInputBox {
6565
border: string;
6666
hoverBorder: string;
6767
textColor: string;
6868
backgroundColor: string;
6969
}
7070

71-
export interface IEmbeddedSwitch {
71+
interface IEmbeddedSwitch {
7272
switchBackground: string;
7373
bulletBorderColor: string;
7474
bulletBGColor: string;

web-app/src/common/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const units = [
3232
"ZiB",
3333
"YiB",
3434
];
35-
export const k8sUnits = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"];
36-
export const k8sCalcUnits = ["B", ...k8sUnits];
35+
const k8sUnits = ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei"];
36+
const k8sCalcUnits = ["B", ...k8sUnits];
3737

3838
export const niceBytes = (x: string, showK8sUnits: boolean = false) => {
3939
let n = parseInt(x, 10) || 0;
@@ -97,7 +97,7 @@ export const getBytes = (
9797
};
9898

9999
//getBytesNumber, converts from a value and a unit from units array to bytes
100-
export const getBytesNumber = (
100+
const getBytesNumber = (
101101
value: string,
102102
unit: string,
103103
fromk8s: boolean = false,

web-app/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { ApplicationLogoProps } from "mds";
1818

19-
export const MinIOPlan =
19+
const MinIOPlan =
2020
(
2121
document.head.querySelector(
2222
"[name~=minio-license][content]",

web-app/src/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React from "react";
18-
import * as serviceWorker from "./serviceWorker";
1918
import ReactDOM from "react-dom/client";
2019
import { Provider } from "react-redux";
2120
import { store } from "./store";
@@ -35,8 +34,3 @@ root.render(
3534
</Provider>
3635
</React.StrictMode>,
3736
);
38-
39-
// If you want your app to work offline and load faster, you can change
40-
// unregister() to register() below. Note this comes with some pitfalls.
41-
// Learn more about service workers: https://bit.ly/CRA-PWA
42-
serviceWorker.unregister();

web-app/src/screens/Console/Buckets/BucketDetails/bucketDetailsSlice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
1818
import { AppState } from "../../../../store";
1919
import { Bucket } from "api/consoleApi";
2020

21-
export interface BucketDetailsState {
21+
interface BucketDetailsState {
2222
selectedTab: string;
2323
loadingBucket: boolean;
2424
bucketInfo: Bucket | null;
@@ -30,7 +30,7 @@ const initialState: BucketDetailsState = {
3030
bucketInfo: null,
3131
};
3232

33-
export const bucketDetailsSlice = createSlice({
33+
const bucketDetailsSlice = createSlice({
3434
name: "bucketDetails",
3535
initialState,
3636
reducers: {
@@ -46,7 +46,7 @@ export const bucketDetailsSlice = createSlice({
4646
},
4747
});
4848

49-
export const { setBucketDetailsTab, setBucketInfo, setBucketDetailsLoad } =
49+
export const { setBucketInfo, setBucketDetailsLoad } =
5050
bucketDetailsSlice.actions;
5151

5252
export const selBucketDetailsLoading = (state: AppState) =>

web-app/src/screens/Console/Buckets/ListBuckets/AddBucket/addBucketsSlice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
1818
import { addBucketAsync } from "./addBucketThunks";
1919
import { ObjectRetentionMode } from "api/consoleApi";
2020

21-
export interface AddBucketState {
21+
interface AddBucketState {
2222
loading: boolean;
2323
isDirty: boolean;
2424
invalidFields: string[];
@@ -58,7 +58,7 @@ const initialState: AddBucketState = {
5858
excludedPrefixes: "",
5959
};
6060

61-
export const addBucketsSlice = createSlice({
61+
const addBucketsSlice = createSlice({
6262
name: "addBuckets",
6363
initialState,
6464
reducers: {

web-app/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjectsHelpers.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { displayFileIconName } from "./utils";
2121

2222
// Functions
2323

24-
export const displayParsedDate = (object: BucketObjectItem) => {
24+
const displayParsedDate = (object: BucketObjectItem) => {
2525
if (object.name.endsWith("/")) {
2626
return "";
2727
}
@@ -41,14 +41,14 @@ export const displayParsedDate = (object: BucketObjectItem) => {
4141
return objectTime.toFormat("ccc, LLL dd yyyy HH:mm (ZZZZ)");
4242
};
4343

44-
export const displayNiceBytes = (object: BucketObjectItem) => {
44+
const displayNiceBytes = (object: BucketObjectItem) => {
4545
if (object.name.endsWith("/") || !object.size) {
4646
return "-";
4747
}
4848
return niceBytes(String(object.size));
4949
};
5050

51-
export const displayDeleteFlag = (state: boolean) => {
51+
const displayDeleteFlag = (state: boolean) => {
5252
return state ? "Yes" : "No";
5353
};
5454

web-app/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/types.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export interface WebsocketResponse {
4545
bucketName?: string;
4646
}
4747

48-
export interface WebsocketErrorResponse {
48+
interface WebsocketErrorResponse {
4949
Code: number;
5050
APIError: ApiError;
5151
}
5252

53-
export interface ObjectResponse {
53+
interface ObjectResponse {
5454
name: string;
5555
last_modified: string;
5656
size: number;

0 commit comments

Comments
 (0)