Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.type-coverage
.yarn/*
!.yarn/patches
!.yarn/plugins
Expand Down
8 changes: 8 additions & 0 deletions doom.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ reference:
sidebar:
collapsed: false
editRepoBaseUrl: alauda/doom/tree/main/docs
lint:
cspellOptions:
cspell:
words:
- artifactcleanupruns
- katanomi
- testplans
- testmodules
18 changes: 9 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ export default config(
eslint.configs.recommended,
importX.flatConfigs.recommended,
importX.flatConfigs.typescript,
configs.eslintRecommended,
...configs.strictTypeChecked,
{
files: ['**/*.{ts,tsx}'],
extends: [configs.eslintRecommended, configs.strictTypeChecked],
languageOptions: {
parserOptions: {
projectService: true,
},
},
settings: {
'import-x/resolver-next': [createTypeScriptImportResolver()],
},
rules: {
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/restrict-template-expressions': [
'error',
{ allowNumber: true },
],
},
},
{
settings: {
'import-x/resolver-next': createTypeScriptImportResolver(),
},
rules: {
'import-x/default': 'off',
'import-x/first': 'error',
'import-x/newline-after-import': 'error',
Expand Down Expand Up @@ -64,8 +68,4 @@ export default config(
'prefer-const': ['error', { destructuring: 'all' }],
},
},
{
files: ['**/*.js'],
...configs.disableTypeChecked,
},
)
15 changes: 15 additions & 0 deletions fixture-docs/doom.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ internalRoutes:
- '*/internal/*.mdx'
- '*/concepts/**'
editRepoBaseUrl: alauda/doom/tree/main/fixture-docs
lint:
cspellOptions:
cspell:
words:
- gatewayview
- netrelationship
- openshiftpipelinesascodes
- tekton
- tektonchains
- tektonconfigs
- tektonhubs
- tektoninstallersets
- tektonpipelines
- tektonresults
- tektontriggers
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"fixture": "yarn dev fixture-docs",
"format": "prettier --write .",
"lint": "run-p 'lint:*'",
"lint:doom": "yarn doom lint",
"lint:es": "eslint . --cache",
"lint:tsc": "tsc -b",
"prepare": "simple-git-hooks && patch-package && yarn-berry-deduplicate || exit 0",
Expand All @@ -56,19 +57,24 @@
"version": "changeset version && yarn --no-immutable"
},
"dependencies": {
"@cspell/eslint-plugin": "^9.0.1",
"@eslint-react/eslint-plugin": "^1.49.0",
"@inquirer/prompts": "^7.5.1",
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
"@playwright/browser-chromium": "^1.52.0",
"@rsbuild/plugin-yaml": "^1.0.2",
"@rspress/core": "1.43.13",
"@shikijs/transformers": "^3.4.0",
"@rspress/core": "1.44.0",
"@shikijs/transformers": "^3.4.2",
"chokidar": "^4.0.3",
"cli-progress": "^3.12.0",
"clsx": "^2.1.1",
"commander": "^13.1.0",
"ejs": "^3.1.10",
"es-toolkit": "^1.37.2",
"eslint": "^9.26.0",
"eslint-plugin-mdx": "^3.4.2",
"html-tag-names": "^2.1.0",
"mdast-util-mdx": "^2.0.1",
"mermaid": "^11.6.0",
"openai": "^5.0.0-beta.0",
"openapi-types": "^12.1.3",
Expand All @@ -82,18 +88,20 @@
"remark-directive": "^2.0.1",
"remark-frontmatter": "^4.0.1",
"remark-gfm": "^3.0.1",
"shiki": "^3.4.0",
"remark-stringify": "^10.0.3",
"shiki": "^3.4.2",
"simple-git": "^3.27.0",
"swagger2openapi": "^7.0.8",
"tinyglobby": "^0.2.13",
"type-fest": "^4.41.0",
"typescript-eslint": "^8.32.1",
"x-fetch": "^0.2.6",
"yaml": "^2.7.1",
"yaml": "^2.8.0",
"yoctocolors": "^2.1.1"
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.29.3",
"@changesets/cli": "^2.29.4",
"@eslint/js": "^9.26.0",
"@swc-node/register": "^1.10.10",
"@swc/core": "1.11.24",
Expand All @@ -107,7 +115,6 @@
"@types/swagger2openapi": "^7.0.4",
"@unts/patch-package": "^8.1.1",
"clean-pkg-json": "^1.3.0",
"eslint": "^9.26.0",
"eslint-import-resolver-typescript": "^4.3.4",
"eslint-plugin-import-x": "^4.11.1",
"nano-staged": "^0.8.0",
Expand All @@ -118,7 +125,6 @@
"simple-git-hooks": "^2.13.0",
"type-coverage": "^2.29.7",
"typescript": "^5.8.3",
"typescript-eslint": "^8.32.0",
"yarn-berry-deduplicate": "^6.1.3"
},
"publishConfig": {
Expand Down
15 changes: 15 additions & 0 deletions src/cli/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import fs from 'node:fs/promises'

import { glob } from 'tinyglobby'
import { xfetch } from 'x-fetch'
import { parse } from 'yaml'

import { FALSY_VALUES } from '../shared/index.js'
import type { NormalizedTermItem } from '../terms.js'

export const parseBoolean = (value: string) =>
!!value && !FALSY_VALUES.has(value)
Expand Down Expand Up @@ -48,3 +51,15 @@ export const defaultGitHubUrl = (url: string) =>
/^https?:\/\//.test(url)
? url
: `https://github.com/${url.replace(/^(\/*github.com)?\/+/i, '')}`

const parseTerms_ = async () => {
const terms = await xfetch(
'https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml',
{ type: 'text' },
)
return parse(terms) as NormalizedTermItem[]
}

let parsedTermsCache: Promise<NormalizedTermItem[]> | undefined

export const parseTerms = () => (parsedTermsCache ??= parseTerms_())
2 changes: 2 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { setNodeEnv } from '../utils/index.js'
import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js'
import { exportCommand } from './export.js'
import { parseBoolean } from './helpers.js'
import { lintCommand } from './lint.js'
import { loadConfig } from './load-config.js'
import { newCommand } from './new.js'
import { translateCommand } from './translate.js'
Expand Down Expand Up @@ -253,6 +254,7 @@ program
program.addCommand(newCommand)
program.addCommand(translateCommand)
program.addCommand(exportCommand)
program.addCommand(lintCommand)

program.parseAsync().catch((err: unknown) => {
if (err instanceof Error && err.name === 'ExitPromptError') {
Expand Down
97 changes: 97 additions & 0 deletions src/cli/lint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import type { Options } from '@cspell/eslint-plugin'
import cspellRecommended from '@cspell/eslint-plugin/recommended'
import js from '@eslint/js'
import react from '@eslint-react/eslint-plugin'
import { Command } from 'commander'
import { merge } from 'es-toolkit/compat'
import { ESLint } from 'eslint'
import * as mdx from 'eslint-plugin-mdx'
import tseslint from 'typescript-eslint'

import type { GlobalCliOptions } from '../types.js'

import { parseTerms } from './helpers.js'
import { loadConfig } from './load-config.js'

export const lintCommand = new Command('lint')
.description('Lint the documentation')
.argument('[root]', 'Root directory of the documentation')
.action(async function (root?: string) {
const globalOptions = this.optsWithGlobals<GlobalCliOptions>()

const { config } = await loadConfig(root, globalOptions)

const docsDir = config.root!

const parsedTerms = await parseTerms()

const eslint = new ESLint({
cwd: docsDir,
// @ts-expect-error -- stronger types
baseConfig: tseslint.config([
{
extends: [
js.configs.recommended,
react.configs.recommended,
mdx.configs.flat,
],
},
{
files: ['**/docs/en/**/*.{js,jsx,md,mdx,ts,tsx}'],
extends: [cspellRecommended],
rules: {
'@cspell/spellchecker': [
'error',
merge(
{
autoFix: true,
cspell: {
words: parsedTerms.map((it) => it.en),
flagWords: parsedTerms.flatMap(
({ badCases }) => badCases?.en ?? [],
),
},
} satisfies Partial<Options>,
config.lint?.cspellOptions,
),
],
},
},
// https://github.com/eslint/eslint/issues/19722
// {
// files: ['**/*.{ts,tsx}'],
// extends: [
// tseslint.configs.recommendedTypeChecked,
// react.configs['recommended-typescript'],
// ],
// rules: {
// '@typescript-eslint/no-misused-promises': 'off',
// '@typescript-eslint/no-non-null-assertion': 'off',
// '@typescript-eslint/restrict-template-expressions': [
// 'error',
// { allowNumber: true },
// ],
// 'prefer-const': ['error', { destructuring: 'all' }],
// },
// languageOptions: {
// parser: tseslint.parser,
// parserOptions: {
// projectService: true,
// },
// },
// },
]),
})

const results = await eslint.lintFiles('**/*.{js,jsx,ts,tsx,md,mdx}')

if (!results.length) {
return
}

process.exitCode = 1

const formatter = await eslint.loadFormatter('stylish')

process.stderr.write(await formatter.format(results))
})
10 changes: 2 additions & 8 deletions src/cli/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import matter from 'gray-matter'
import { AzureOpenAI, RateLimitError } from 'openai'
import { pRateLimit } from 'p-ratelimit'
import { glob } from 'tinyglobby'
import { xfetch } from 'x-fetch'
import { parse } from 'yaml'
import { cyan, red } from 'yoctocolors'

import {
Expand All @@ -24,14 +22,14 @@ import {
type NormalizeImgSrcOptions,
} from '../plugins/index.js'
import { Language, SUPPORTED_LANGUAGES } from '../shared/index.js'
import type { NormalizedTermItem } from '../terms.js'
import type { GlobalCliOptions, TranslateOptions } from '../types.js'
import { pathExists } from '../utils/index.js'

import {
escapeMarkdownHeadingIds,
getMatchedDocFilePaths,
parseBoolean,
parseTerms,
} from './helpers.js'
import { loadConfig } from './load-config.js'

Expand Down Expand Up @@ -98,11 +96,7 @@ export interface InternalTranslateOptions extends TranslateOptions {
}

const resolveTerms_ = async () => {
const terms = await xfetch(
'https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml',
{ type: 'text' },
)
const parsedTerms = parse(terms) as NormalizedTermItem[]
const parsedTerms = await parseTerms()
return (
'- 以下是常见的相关术语词汇对应表(English <-> 中文)\n' +
parsedTerms.map(({ en, zh = en }) => ` * ${en} <-> ${zh}`).join('\n')
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Options } from '@cspell/eslint-plugin'
import type { serve } from '@rspress/core'

import type {
Expand Down Expand Up @@ -37,6 +38,10 @@ export interface TranslateOptions {
userPrompt?: string
}

export interface LintOptions {
cspellOptions?: Partial<Options>
}

declare module '@rspress/shared' {
interface UserConfig {
prefix?: string
Expand All @@ -51,6 +56,7 @@ declare module '@rspress/shared' {
translate?: TranslateOptions
shiki?: PluginShikiOptions
editRepoBaseUrl?: string
lint?: LintOptions
}

interface SiteData {
Expand Down
Loading
Loading