Skip to content

Commit 7f1d1ba

Browse files
committed
Shared now lints itself
1 parent fe0f7c5 commit 7f1d1ba

File tree

12 files changed

+112
-78
lines changed

12 files changed

+112
-78
lines changed

.github/workflows/shared.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Shared
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
merge_group:
9+
10+
jobs:
11+
build-and-test:
12+
name: Shared Build and Lint
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
# Needed to copy the WASM file during build
19+
lfs: true
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "24"
24+
- name: Install dependencies
25+
run: npm ci
26+
- name: Lint
27+
working-directory: ./packages/shared
28+
run: npm run lint
29+
- name: Type check
30+
working-directory: ./packages/shared
31+
run: npm run type-check
32+
- name: Build
33+
working-directory: ./packages/shared
34+
run: npm run build

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { resolve } from "node:path";
22

3-
import { getReactEslintConfig } from "@speakeasy-api/config";
3+
import { getReactEslintConfig } from "@speakeasy-api/docs-md-shared";
44
import { getDirname } from "cross-dirname";
55
import globals from "globals";
66

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"dependencies": {
3535
"@codesandbox/sandpack-client": "^2.19.8",
3636
"@codesandbox/sandpack-react": "^2.20.0",
37+
"@speakeasy-api/docs-md-shared": "*",
3738
"arg": "^5.0.2",
3839
"chalk": "^5.3.0",
3940
"change-case": "^5.4.4",

packages/shared/eslint.config.mjs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
import { resolve } from "node:path";
22

3-
import { getReactEslintConfig } from "@speakeasy-api/shared";
43
import { getDirname } from "cross-dirname";
5-
import globals from "globals";
4+
5+
import { getNodeESLintConfig } from "./index.mjs";
66

77
const gitignorePath = resolve(getDirname(), "..", "..", ".gitignore");
88

99
export default [
10-
...getReactEslintConfig({
10+
...getNodeESLintConfig({
1111
gitignorePaths: gitignorePath,
1212
rootDir: getDirname(),
1313
entryPoints: {
1414
"eslint.config.mjs": ["default"],
15+
"index.mjs": /.*/,
1516
"types/index.ts": /.*/,
1617
},
17-
// Since we're a mix of running in both Node.js and React, we override the
18-
// globals set by the React config to include Node.js globals as well.
19-
{
20-
languageOptions: {
21-
globals: { ...globals.browser, ...globals.node },
22-
},
23-
},
24-
// Disable unused exports rule for Storybook files
25-
{
26-
files: ["**/*.stories.{ts,tsx}", ".storybook/*.{ts,tsx}"],
27-
rules: {
28-
"fast-import/no-unused-exports": "off",
29-
},
30-
},
31-
// Disallow console calls in compiler code (use logging.ts functions instead)
32-
{
33-
files: ["src/compiler/**/*.{ts,js,mts,mjs}"],
34-
ignores: ["src/compiler/logging.ts"],
35-
rules: {
36-
"no-console": "error",
37-
},
38-
},
18+
ignores: ["src/compiler/data/wasm_exec.js"],
19+
restrictedImports: [
20+
{
21+
type: "third-party",
22+
moduleSpecifier: "node:fs",
23+
allowed: [/src\/compiler\/cli\//],
24+
message:
25+
"File system access is only allowed in the CLI wrapper because other code needs to be isomorphic",
26+
},
27+
],
28+
}),
3929
];

packages/shared/eslint/base.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import { includeIgnoreFile } from "@eslint/compat";
12
import eslint from "@eslint/js";
2-
import tseslint from "typescript-eslint";
3+
import { globalIgnores } from "eslint/config";
34
import eslintConfigPrettier from "eslint-config-prettier/flat";
4-
import unusedImports from "eslint-plugin-unused-imports";
5-
import { includeIgnoreFile } from "@eslint/compat";
65
import { all } from "eslint-plugin-fast-import";
76
import simpleImportSort from "eslint-plugin-simple-import-sort";
8-
import { globalIgnores } from "eslint/config";
7+
import unusedImports from "eslint-plugin-unused-imports";
8+
import tseslint from "typescript-eslint";
99

10-
export const getBaseESLintConfig = ({
10+
export function getBaseESLintConfig({
1111
gitignorePaths,
1212
rootDir,
1313
entryPoints,
1414
ignores,
1515
restrictedImports,
16-
}) => {
16+
}) {
1717
if (!Array.isArray(gitignorePaths)) {
1818
gitignorePaths = [gitignorePaths];
1919
}
@@ -95,4 +95,4 @@ export const getBaseESLintConfig = ({
9595
},
9696
},
9797
];
98-
};
98+
}

packages/shared/eslint/node.mjs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import ava from "eslint-plugin-ava";
12
import globals from "globals";
3+
24
import { getBaseESLintConfig } from "./base.mjs";
3-
import ava from "eslint-plugin-ava";
45

5-
export const getNodeESLintConfig = (options) => [
6-
...getBaseESLintConfig(options),
7-
ava.configs["flat/recommended"],
8-
{
9-
languageOptions: {
10-
globals: globals.node,
11-
},
12-
rules: {
13-
// This rule doesn't support TypeScript tests
14-
"ava/no-ignored-test-files": "off",
6+
export function getNodeESLintConfig(options) {
7+
return [
8+
...getBaseESLintConfig(options),
9+
ava.configs["flat/recommended"],
10+
{
11+
languageOptions: {
12+
globals: globals.node,
13+
},
14+
rules: {
15+
// This rule doesn't support TypeScript tests
16+
"ava/no-ignored-test-files": "off",
17+
},
1518
},
16-
},
17-
];
19+
];
20+
}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import playwright from "eslint-plugin-playwright";
12
import globals from "globals";
3+
24
import { getBaseESLintConfig } from "./base.mjs";
3-
import playwright from "eslint-plugin-playwright";
45

5-
export const getPlaywrightESLintConfig = (options) => [
6-
...getBaseESLintConfig(options),
7-
playwright.configs["flat/recommended"],
8-
{ languageOptions: { globals: globals.node } },
9-
];
6+
export function getPlaywrightESLintConfig(options) {
7+
return [
8+
...getBaseESLintConfig(options),
9+
playwright.configs["flat/recommended"],
10+
{ languageOptions: { globals: globals.node } },
11+
];
12+
}

packages/shared/eslint/react.mjs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import globals from "globals";
2-
import { getBaseESLintConfig } from "./base.mjs";
31
import pluginReact from "eslint-plugin-react";
42
import reactHooks from "eslint-plugin-react-hooks";
3+
import globals from "globals";
54

6-
export const getReactEslintConfig = (options) => [
7-
...getBaseESLintConfig(options),
8-
pluginReact.configs.flat.recommended,
9-
reactHooks.configs["recommended-latest"],
10-
{
11-
languageOptions: {
12-
globals: globals.browser,
13-
},
14-
settings: {
15-
react: {
16-
version: "detect",
5+
import { getBaseESLintConfig } from "./base.mjs";
6+
7+
export function getReactEslintConfig(options) {
8+
return [
9+
...getBaseESLintConfig(options),
10+
pluginReact.configs.flat.recommended,
11+
reactHooks.configs["recommended-latest"],
12+
{
13+
languageOptions: {
14+
globals: globals.browser,
15+
},
16+
settings: {
17+
react: {
18+
version: "detect",
19+
},
20+
},
21+
rules: {
22+
"react-hooks/exhaustive-deps": "error",
1723
},
1824
},
19-
rules: {
20-
"react-hooks/exhaustive-deps": "error",
21-
},
22-
},
23-
{
24-
rules: {
25-
"react/react-in-jsx-scope": "off",
25+
{
26+
rules: {
27+
"react/react-in-jsx-scope": "off",
28+
},
2629
},
27-
},
28-
];
30+
];
31+
}

packages/shared/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"build": "",
3232
"dev": "",
3333
"format": "prettier --config ../../prettier.config.mjs --ignore-path ../../.gitignore --write \"**/*.{js,jsx,mjs,ts,tsx,mts}\"",
34-
"lint": "",
34+
"lint": "eslint \"**/*.{js,jsx,mjs,ts,tsx,mts}\"",
3535
"start": "",
3636
"test": "",
37-
"type-check": "",
37+
"type-check": "tsc --noEmit",
3838
"build-api-docs": ""
3939
}
4040
}

0 commit comments

Comments
 (0)