Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8fde3ed

Browse files
author
G r e y
authored
chore: improve eslint, sb, tsc configs (#483)
Summary: This commit is a bit of a shotgun fix for various project settings. Realistically, they could've been separate commits, but this is convenience for just getting things into a green state to unblock further work. Details: - Use our version of TS in vscode plugins - organize vscode/settings.json - fix tsconfig.test and tsconfig.prod (removes errors in test files) - only use prod tsconfig in webpack - point .eslintrc to both test and prod configs - cleanup storybook - running eslint in my workspace was OOMing. I configured maxWorkers like we had in v1 to fix this. - remove .storybook from code coverage - remove .js files from code coverage --> after moving away from Next.js, we don't allowJS in our tsconfig anymore. We only use JS for configurations, it's not allowed in src code!
1 parent d875298 commit 8fde3ed

12 files changed

+86
-40
lines changed

.vscode/settings.json

+31-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
{
2-
"files.exclude": {
3-
"**/node_modules": true
4-
},
5-
"go.lintTool": "golangci-lint",
6-
"go.lintFlags": ["--fast"],
7-
"go.lintOnSave": "package",
8-
"go.coverOnSave": true,
9-
// The codersdk is used by coderd another other packages extensively.
10-
// To reduce redundancy in tests, it's covered by other packages.
11-
"go.testFlags": ["-coverpkg=./.,github.com/coder/coder/codersdk"],
12-
"go.coverageDecorator": {
13-
"type": "gutter",
14-
"coveredHighlightColor": "rgba(64,128,128,0.5)",
15-
"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
16-
"coveredBorderColor": "rgba(64,128,128,0.5)",
17-
"uncoveredBorderColor": "rgba(128,64,64,0.25)",
18-
"coveredGutterStyle": "blockgreen",
19-
"uncoveredGutterStyle": "blockred"
20-
},
21-
"emeraldwalk.runonsave": {
22-
"commands": [
23-
{
24-
"match": "database/query.sql",
25-
"cmd": "make gen"
26-
}
27-
]
28-
},
292
"cSpell.words": [
303
"coderd",
314
"coderdtest",
@@ -76,5 +49,35 @@
7649
"xerrors",
7750
"yamux"
7851
],
79-
"eslint.workingDirectories": ["./site"]
52+
"emeraldwalk.runonsave": {
53+
"commands": [
54+
{
55+
"match": "database/query.sql",
56+
"cmd": "make gen"
57+
}
58+
]
59+
},
60+
"eslint.workingDirectories": ["./site"],
61+
"files.exclude": {
62+
"**/node_modules": true
63+
},
64+
"go.lintTool": "golangci-lint",
65+
"go.lintFlags": ["--fast"],
66+
"go.lintOnSave": "package",
67+
"go.coverOnSave": true,
68+
// The codersdk is used by coderd another other packages extensively.
69+
// To reduce redundancy in tests, it's covered by other packages.
70+
"go.testFlags": ["-coverpkg=./.,github.com/coder/coder/codersdk"],
71+
"go.coverageDecorator": {
72+
"type": "gutter",
73+
"coveredHighlightColor": "rgba(64,128,128,0.5)",
74+
"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
75+
"coveredBorderColor": "rgba(64,128,128,0.5)",
76+
"uncoveredBorderColor": "rgba(128,64,64,0.25)",
77+
"coveredGutterStyle": "blockgreen",
78+
"uncoveredGutterStyle": "blockred"
79+
},
80+
// We often use a version of TypeScript that's ahead of the version shipped
81+
// with VS Code.
82+
"typescript.tsdk": "./site/node_modules/typescript/lib"
8083
}

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ ignore:
3535
- provisionerd/proto
3636
- provisionersdk/proto
3737
- scripts/datadog-cireport
38+
- site/.storybook
3839
- rules.go

site/.eslintrc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extends:
1717
parser: "@typescript-eslint/parser"
1818
parserOptions:
1919
ecmaVersion: 2018
20-
project: "./tsconfig.test.json"
20+
project: "./tsconfig.json"
2121
sourceType: module
2222
ecmaFeatures:
2323
jsx: true

site/.storybook/main.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1+
/**
2+
* @fileoverview This file is configures Storybook
3+
*
4+
* @see <https://storybook.js.org/docs/react/configure/overview>
5+
*/
16
const path = require("path")
27

38
module.exports = {
4-
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
9+
// Automatically loads all stories in source ending in 'stories.tsx'
10+
//
11+
// SEE: https://storybook.js.org/docs/react/configure/overview#configure-story-loading
12+
stories: ["../src/**/*.stories.tsx"],
13+
14+
// addons are official and community plugins to extend Storybook.
15+
//
16+
// SEE: https://storybook.js.org/addons
517
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
18+
19+
// Storybook uses babel under the hood, while we currently use ts-loader.
20+
// Sometimes, you may encounter an error in a Storybook that contains syntax
21+
// that requires a babel plugin.
22+
//
23+
// SEE: https://storybook.js.org/docs/react/configure/babel
624
babel: async (options) => ({
725
...options,
826
plugins: ["@babel/plugin-proposal-class-properties"],
9-
// any extra options you want to set
1027
}),
28+
29+
// Storybook internally uses its own Webpack configuration instead of ours.
30+
//
31+
// SEE: https://storybook.js.org/docs/react/configure/webpack
1132
webpackFinal: async (config) => {
1233
config.resolve.modules = [path.resolve(__dirname, ".."), "node_modules"]
13-
1434
return config
1535
},
1636
}

site/jest.config.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
// REMARK: Jest is supposed to never exceed 50% maxWorkers by default. However,
2+
// there seems to be an issue with this in our Ubuntu-based workspaces.
3+
// If we don't limit it, then 100% CPU and high MEM usage is hit
4+
// unexpectedly, leading to OOM kills.
5+
//
6+
// SEE thread: https://github.com/coder/coder/pull/483#discussion_r829636583
7+
const maxWorkers = process.env.CI ? 16 : 2
8+
19
module.exports = {
10+
maxWorkers,
211
projects: [
312
{
413
globals: {
514
"ts-jest": {
6-
tsconfig: "tsconfig.test.json",
15+
tsconfig: "./tsconfig.test.json",
716
},
817
},
918
coverageReporters: ["text", "lcov"],
@@ -28,9 +37,10 @@ module.exports = {
2837
},
2938
],
3039
collectCoverageFrom: [
31-
"<rootDir>/**/*.js",
40+
// included files
3241
"<rootDir>/**/*.ts",
3342
"<rootDir>/**/*.tsx",
43+
// excluded files
3444
"!<rootDir>/**/*.stories.tsx",
3545
"!<rootDir>/_jest/**/*.*",
3646
"!<rootDir>/api.ts",

site/src/components/CodeBlock/index.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Started container user
99
Using user 'coder' with shell '/bin/bash'`.split("\n")
1010

1111
export default {
12-
title: "CodeBlock",
12+
title: "CodeBlock/CodeBlock",
1313
component: CodeBlock,
1414
argTypes: {
1515
lines: { control: "text", defaultValue: sampleLines },

site/src/components/CodeExample/CodeExample.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CodeExample, CodeExampleProps } from "./CodeExample"
55
const sampleCode = `echo "Hello, world"`
66

77
export default {
8-
title: "CodeExample",
8+
title: "CodeBlock/CodeExample",
99
component: CodeExample,
1010
argTypes: {
1111
code: { control: "string", defaultValue: sampleCode },

site/src/components/Workspace/Workspace.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Workspace, WorkspaceProps } from "./Workspace"
44
import { MockOrganization, MockProject, MockWorkspace } from "../../test_helpers"
55

66
export default {
7-
title: "Workspace",
7+
title: "Workspaces/Workspace",
88
component: Workspace,
99
argTypes: {},
1010
}

site/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"target": "es5"
1717
},
1818
"include": ["**/*.ts", "**/*.tsx"],
19-
"exclude": ["node_modules", "_jest", "**/*.test.tsx"]
19+
"exclude": ["node_modules", "_jest"]
2020
}

site/tsconfig.prod.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["node_modules", "_jest", "**/*.stories.tsx", "**/*.test.tsx"]
4+
}

site/tsconfig.test.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": ["node_modules", "_jest"]
3+
"exclude": ["node_modules", "_jest"],
4+
"include": ["**/*.stories.tsx", "**/*.test.tsx"]
45
}

site/webpack.common.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export const commonWebpackConfig: Configuration = {
3030
rules: [
3131
{
3232
test: /\.tsx?$/,
33-
use: ["ts-loader"],
33+
use: [
34+
{
35+
loader: "ts-loader",
36+
options: {
37+
configFile: "tsconfig.prod.json",
38+
},
39+
},
40+
],
3441
exclude: [/node_modules/],
3542
},
3643
],

0 commit comments

Comments
 (0)