Skip to content

Commit

Permalink
Merge pull request #210 from xen0n/linting
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
xen0n authored Oct 26, 2024
2 parents e683b73 + eb8403f commit f6cb3d8
Show file tree
Hide file tree
Showing 49 changed files with 2,122 additions and 862 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.css,*.js,*.json,*.ts,*.tsx,*.yaml,*.yml}]
[{*.css,*.cjs,*.cts,*.js,*.json,*.mjs,*.mts,*.ts,*.tsx,*.yaml,*.yml}]
indent_size = 2

[*.md]
[{*.md,*.mdx}]
indent_size = 4

[*.go]
Expand Down
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: yarn
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /scripts/asmdb
schedule:
interval: weekly
29 changes: 29 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR checks

on:
pull_request:

jobs:
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Check out the source code
uses: actions/checkout@v4
with:
submodules: true
- name: Enable Corepack for Yarn Modern
run: corepack enable
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Install dependencies
run: yarn install --immutable
- name: Check code style with Prettier
run: yarn prettier --check .
- name: Lint with ESLint
run: yarn eslint
- name: Type-check with tsc
run: yarn tsc
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.github
/.vscode
/.yarn
/3rdparty
/build
/node_modules
/scripts
/static
/yarn.lock
*.md
*.mdx
7 changes: 7 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tabWidth = 2
semi = false
singleQuote = true

[[overrides]]
files = ["*.md", "*.mdx"]
options = { tabWidth = 4 }
5 changes: 5 additions & 0 deletions babel.config.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import docusaurusPreset from '@docusaurus/core/lib/babel/preset'

export default {
presets: [docusaurusPreset],
}
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

18 changes: 9 additions & 9 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ const config: Config = {
routeBasePath: 'newsletter',
path: './newsletter',
blogTitle: '每周一龙',
blogDescription: '龙架构新世界生态建设周报《每周一龙》(This Week in LoongArch)。每周一都为大家报道 LoongArch 社区最前线的第一手新鲜资讯!',
editUrl: 'https://github.com/loongson-community/areweloongyet/edit/main',
blogDescription:
'龙架构新世界生态建设周报《每周一龙》(This Week in LoongArch)。每周一都为大家报道 LoongArch 社区最前线的第一手新鲜资讯!',
editUrl:
'https://github.com/loongson-community/areweloongyet/edit/main',
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
rehypePlugins: commonRehypePlugins,
onUntruncatedBlogPosts: 'throw',
onUntruncatedBlogPosts: 'throw',
} satisfies BlogOptions,
],
],
Expand All @@ -171,8 +173,7 @@ const config: Config = {
sidebarPath: require.resolve('./sidebars.js'),
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/loongson-community/areweloongyet',
editUrl: 'https://github.com/loongson-community/areweloongyet',
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
rehypePlugins: commonRehypePlugins,
},
Expand All @@ -182,11 +183,10 @@ const config: Config = {
showReadingTime: true,
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/loongson-community/areweloongyet',
editUrl: 'https://github.com/loongson-community/areweloongyet',
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
rehypePlugins: commonRehypePlugins,
onUntruncatedBlogPosts: 'throw',
onUntruncatedBlogPosts: 'throw',
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
Expand All @@ -199,7 +199,7 @@ const config: Config = {
[
'@easyops-cn/docusaurus-search-local',
{
hashed: "filename",
hashed: 'filename',
language: ['en', 'zh'],
blogDir: ['blog', 'newsletter'],
blogRouteBasePath: ['/blog', '/newsletter'],
Expand Down
28 changes: 28 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @ts-check

import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ['.docusaurus/', '.yarn/', '.pnp.*', 'build/'],
},
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
},
)
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@
"devDependencies": {
"@docusaurus/module-type-aliases": "3.5.2",
"@docusaurus/tsconfig": "3.5.2",
"@eslint/js": "^9.13.0",
"@types/eslint__js": "^8.42.3",
"@types/glob": "^8.1.0",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.10",
"@types/mdast": "^4.0.4",
"@types/node": "^22.7.5",
"@types/prismjs": "^1.26.4",
"@types/react": "^18.3.11",
"@types/react-router-dom": "^5.3.3",
"eslint": "^9.13.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0",
"update-browserslist-db": "^1.1.1"
},
"resolutions": {
Expand All @@ -77,5 +83,5 @@
"engines": {
"node": ">=20"
},
"packageManager": "[email protected].0"
"packageManager": "[email protected].1"
}
6 changes: 3 additions & 3 deletions sidebars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs'
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs'

const sidebars: SidebarsConfig = {
main: [{type: 'autogenerated', dirName: '.'}],
};
main: [{ type: 'autogenerated', dirName: '.' }],
}

export default sidebars
119 changes: 86 additions & 33 deletions src/components/AsmDB/antdDecodeTreeAdapter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Tag, type TreeDataNode } from "antd"
import { Tag, type TreeDataNode } from 'antd'
import { CheckOutlined, EyeOutlined } from '@ant-design/icons'
import _ from 'lodash'

import styles from './index.module.css'
import { type AugmentedDecodeTreeMatch, type AugmentedDecodeTreeNode } from "./augmentedDecodeTree"
import { bitfieldWidth, representBitfields } from "./bitfield"
import type { Bitfield } from "./types"
import {
type AugmentedDecodeTreeMatch,
type AugmentedDecodeTreeNode,
} from './augmentedDecodeTree'
import { bitfieldWidth, representBitfields } from './bitfield'
import type { Bitfield } from './types'

function representMatchValue(val: number, bfs: Bitfield[]): string {
const sortedBFs = _.sortBy(_.clone(bfs), 'lsb')
Expand All @@ -24,10 +27,8 @@ type NodeTitleProps = {
node?: AugmentedDecodeTreeNode
}


function NodeTitle({ match, node }: NodeTitleProps): JSX.Element {
if (!match)
match = node.parentMatch
if (!match) match = node.parentMatch

const matchNumber = match ? match.match : 0
const matchPattern = node ? node.key : match.key
Expand All @@ -40,57 +41,109 @@ function NodeTitle({ match, node }: NodeTitleProps): JSX.Element {
const postAttribs: JSX.Element[] = []
if (match?.fmt)
if (node)
postAttribs.push(<span className={styles.contentAttrib} key={`${matchPattern}-fmt`}>并确定格式为 {match.fmt}</span>)
postAttribs.push(
<span className={styles.contentAttrib} key={`${matchPattern}-fmt`}>
并确定格式为 {match.fmt}
</span>,
)
else
postAttribs.push(<Tag className={styles.insnFmtTagAttrib} key={`${matchPattern}-fmt`}>{match.fmt}</Tag>)
postAttribs.push(
<Tag className={styles.insnFmtTagAttrib} key={`${matchPattern}-fmt`}>
{match.fmt}
</Tag>,
)
if (alias)
preAttribs.push(<Tag className={styles.aliasTagAttrib} key={`${matchPattern}-alias`}>{alias}</Tag>)
preAttribs.push(
<Tag className={styles.aliasTagAttrib} key={`${matchPattern}-alias`}>
{alias}
</Tag>,
)

if (insn) {
return <>
<span>{representMatchValue(matchNumber, lookAt)}: {preAttribs}{insn}</span>
{postAttribs}
</>
return (
<>
<span>
{representMatchValue(matchNumber, lookAt)}: {preAttribs}
{insn}
</span>
{postAttribs}
</>
)
}

const root = matchPattern == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
if (root)
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-major`}>主操作码</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-major`}>
主操作码
</span>,
)
if (node) {
const numAllocatedPrefixes = node.matches.length
const numTotalPrefixes = 1 << bitfieldWidth(node.look_at)
if (numAllocatedPrefixes == numTotalPrefixes && node.numUsedInsnWords == node.numTotalInsnWords) {
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-subspace`}>子空间已满</span>)
if (
numAllocatedPrefixes == numTotalPrefixes &&
node.numUsedInsnWords == node.numTotalInsnWords
) {
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-subspace`}>
子空间已满
</span>,
)
} else {
if (numAllocatedPrefixes == numTotalPrefixes)
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-fanout`}>子前缀空间已满</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-fanout`}>
子前缀空间已满
</span>,
)
else
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-fanout`}>子前缀空间 {numAllocatedPrefixes}/{numTotalPrefixes}</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-fanout`}>
子前缀空间 {numAllocatedPrefixes}/{numTotalPrefixes}
</span>,
)

if (node.numUsedInsnWords == node.numTotalInsnWords)
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-subspace`}>子编码空间已满</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-subspace`}>
子编码空间已满
</span>,
)
else
postAttribs.push(<span className={styles.attrib} key={`${matchPattern}-subspace`}>子编码空间已用 {(node.numUsedInsnWords / node.numTotalInsnWords * 100).toFixed(2)}%</span>)
postAttribs.push(
<span className={styles.attrib} key={`${matchPattern}-subspace`}>
子编码空间已用{' '}
{((node.numUsedInsnWords / node.numTotalInsnWords) * 100).toFixed(
2,
)}
%
</span>,
)
}
}

if (root)
return <>
<span>检查 [{representBitfields(lookAt)}] 位</span>
return (
<>
<span>检查 [{representBitfields(lookAt)}] 位</span>
{postAttribs}
</>
)

return (
<>
<span>
{representMatchValue(matchNumber, parentLookAt)}: {preAttribs}检查 [
{representBitfields(lookAt)}] 位
</span>
{postAttribs}
</>

return <>
<span>{representMatchValue(matchNumber, parentLookAt)}: {preAttribs}检查 [{representBitfields(lookAt)}] 位</span>
{postAttribs}
</>
)
}

function makeMatchNode(
m: AugmentedDecodeTreeMatch,
): TreeDataNode {
if (m.next)
return transformDecodeTreeForAntd(m.next)
function makeMatchNode(m: AugmentedDecodeTreeMatch): TreeDataNode {
if (m.next) return transformDecodeTreeForAntd(m.next)

return {
title: <NodeTitle match={m} />,
Expand Down
Loading

0 comments on commit f6cb3d8

Please sign in to comment.