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

Skip to content

chore: improve eslint, sb, tsc configs #483

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

Merged
merged 6 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 31 additions & 28 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file was:

  • re-organized (alphabetically). Reason = "at a glance" behaviors.
  • we point vscode plugins to use our version of TS installed, not the version shipped with vs code (this fixes various problems in reading tsconfig files and red squiggly lines showing up in files)

"files.exclude": {
"**/node_modules": true
},
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast"],
"go.lintOnSave": "package",
"go.coverOnSave": true,
// The codersdk is used by coderd another other packages extensively.
// To reduce redundancy in tests, it's covered by other packages.
"go.testFlags": ["-coverpkg=./.,github.com/coder/coder/codersdk"],
"go.coverageDecorator": {
"type": "gutter",
"coveredHighlightColor": "rgba(64,128,128,0.5)",
"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
"coveredBorderColor": "rgba(64,128,128,0.5)",
"uncoveredBorderColor": "rgba(128,64,64,0.25)",
"coveredGutterStyle": "blockgreen",
"uncoveredGutterStyle": "blockred"
},
"emeraldwalk.runonsave": {
"commands": [
{
"match": "database/query.sql",
"cmd": "make gen"
}
]
},
"cSpell.words": [
"coderd",
"coderdtest",
Expand Down Expand Up @@ -76,5 +49,35 @@
"xerrors",
"yamux"
],
"eslint.workingDirectories": ["./site"]
"emeraldwalk.runonsave": {
"commands": [
{
"match": "database/query.sql",
"cmd": "make gen"
}
]
},
"eslint.workingDirectories": ["./site"],
"files.exclude": {
"**/node_modules": true
},
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast"],
"go.lintOnSave": "package",
"go.coverOnSave": true,
// The codersdk is used by coderd another other packages extensively.
// To reduce redundancy in tests, it's covered by other packages.
"go.testFlags": ["-coverpkg=./.,github.com/coder/coder/codersdk"],
"go.coverageDecorator": {
"type": "gutter",
"coveredHighlightColor": "rgba(64,128,128,0.5)",
"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
"coveredBorderColor": "rgba(64,128,128,0.5)",
"uncoveredBorderColor": "rgba(128,64,64,0.25)",
"coveredGutterStyle": "blockgreen",
"uncoveredGutterStyle": "blockred"
},
// We often use a version of TypeScript that's ahead of the version shipped
// with VS Code.
"typescript.tsdk": "./site/node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ ignore:
- provisionerd/proto
- provisionersdk/proto
- scripts/datadog-cireport
- site/.storybook
- rules.go
2 changes: 1 addition & 1 deletion site/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extends:
parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: 2018
project: "./tsconfig.test.json"
project: "./tsconfig.json"
sourceType: module
ecmaFeatures:
jsx: true
Expand Down
26 changes: 23 additions & 3 deletions site/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
/**
* @fileoverview This file is configures Storybook
*
* @see <https://storybook.js.org/docs/react/configure/overview>
*/
const path = require("path")

module.exports = {
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
// Automatically loads all stories in source ending in 'stories.tsx'
//
// SEE: https://storybook.js.org/docs/react/configure/overview#configure-story-loading
stories: ["../src/**/*.stories.tsx"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simplified this for now because:

  1. it's just easier to understand like this
  2. we don't have use-cases or scenarios for mdx or ts stories
  3. changing this to accommodate mdx or ts files later is trivial

Copy link
Contributor

@bryphe-coder bryphe-coder Mar 18, 2022

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a similar commit in an unpushed branch for v1, yes! Good call!


// addons are official and community plugins to extend Storybook.
//
// SEE: https://storybook.js.org/addons
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],

// Storybook uses babel under the hood, while we currently use ts-loader.
// Sometimes, you may encounter an error in a Storybook that contains syntax
// that requires a babel plugin.
//
// SEE: https://storybook.js.org/docs/react/configure/babel
babel: async (options) => ({
...options,
plugins: ["@babel/plugin-proposal-class-properties"],
// any extra options you want to set
}),

// Storybook internally uses its own Webpack configuration instead of ours.
//
// SEE: https://storybook.js.org/docs/react/configure/webpack
webpackFinal: async (config) => {
config.resolve.modules = [path.resolve(__dirname, ".."), "node_modules"]

return config
},
}
14 changes: 12 additions & 2 deletions site/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// REMARK: Jest is supposed to never exceed 50% maxWorkers by default. However,
// there seems to be an issue with this in our Ubuntu-based workspaces.
// If we don't limit it, then 100% CPU and high MEM usage is hit
// unexpectedly, leading to OOM kills.
//
// SEE thread: https://github.com/coder/coder/pull/483#discussion_r829636583
const maxWorkers = process.env.CI ? 16 : 2

module.exports = {
maxWorkers,
projects: [
{
globals: {
"ts-jest": {
tsconfig: "tsconfig.test.json",
tsconfig: "./tsconfig.test.json",
},
},
coverageReporters: ["text", "lcov"],
Expand All @@ -28,9 +37,10 @@ module.exports = {
},
],
collectCoverageFrom: [
"<rootDir>/**/*.js",
// included files
"<rootDir>/**/*.ts",
"<rootDir>/**/*.tsx",
// excluded files
"!<rootDir>/**/*.stories.tsx",
"!<rootDir>/_jest/**/*.*",
"!<rootDir>/api.ts",
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/CodeBlock/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Started container user
Using user 'coder' with shell '/bin/bash'`.split("\n")

export default {
title: "CodeBlock",
title: "CodeBlock/CodeBlock",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two types of CodeBlocks, so I organized them. Furthermore, this makes it so that every current story has a top-level heading, which is visually appealing.

component: CodeBlock,
argTypes: {
lines: { control: "text", defaultValue: sampleLines },
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/CodeExample/CodeExample.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CodeExample, CodeExampleProps } from "./CodeExample"
const sampleCode = `echo "Hello, world"`

export default {
title: "CodeExample",
title: "CodeBlock/CodeExample",
component: CodeExample,
argTypes: {
code: { control: "string", defaultValue: sampleCode },
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Workspace, WorkspaceProps } from "./Workspace"
import { MockOrganization, MockProject, MockWorkspace } from "../../test_helpers"

export default {
title: "Workspace",
title: "Workspaces/Workspace",
component: Workspace,
argTypes: {},
}
Expand Down
2 changes: 1 addition & 1 deletion site/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"target": "es5"
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "_jest", "**/*.test.tsx"]
"exclude": ["node_modules", "_jest"]
}
4 changes: 4 additions & 0 deletions site/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "_jest", "**/*.stories.tsx", "**/*.test.tsx"]
}
3 changes: 2 additions & 1 deletion site/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "_jest"]
"exclude": ["node_modules", "_jest"],
"include": ["**/*.stories.tsx", "**/*.test.tsx"]
}
9 changes: 8 additions & 1 deletion site/webpack.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export const commonWebpackConfig: Configuration = {
rules: [
{
test: /\.tsx?$/,
use: ["ts-loader"],
use: [
{
loader: "ts-loader",
options: {
configFile: "tsconfig.prod.json",
},
},
],
exclude: [/node_modules/],
},
],
Expand Down