Skip to content

Commit

Permalink
🔧 chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
guanghechen committed Sep 20, 2024
1 parent e509173 commit 224e248
Show file tree
Hide file tree
Showing 28 changed files with 154 additions and 155 deletions.
4 changes: 2 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
nodeLinker: node-modules

npmRegistryServer: "https://registry.npmjs.org/"
npmRegistryServer: 'https://registry.npmjs.org/'

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
spec: '@yarnpkg/plugin-interactive-tools'

preferInteractive: true

Expand Down
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ export default [
{
files: ['**/src/**/*.ts'],
rules: {
'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'import/no-named-as-default': 'off',
'space-in-parens': 'off',
},
},
]
1 change: 0 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-extraneous-dependencies */
import { tsMonorepoConfig } from '@guanghechen/jest-config'
import path from 'node:path'
import url from 'node:url'
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
"@guanghechen/conventional-changelog": "^6.0.0-alpha.2",
"@guanghechen/eslint-config": "^7.0.4",
"@guanghechen/helper-jest": "^6.0.0-alpha.5",
"@guanghechen/helper-string": "^6.0.0-alpha.2",
"@guanghechen/jest-config": "^6.0.0-alpha.2",
"@guanghechen/reporter": "^1.0.0",
"@guanghechen/rollup-config": "^6.0.0-alpha.6",
"@guanghechen/script-doc-link": "^6.0.0-alpha.17",
"@guanghechen/string": "^1.0.1",
"@types/jest": "29.5.13",
"@types/node": "^20.16.5",
"cross-env": "^7.0.3",
Expand All @@ -74,7 +74,7 @@
"pinst": "3.0.0",
"prettier": "3.3.3",
"rimraf": "^6.0.1",
"rollup": "^4.22.0",
"rollup": "^4.22.1",
"ts-jest": "29.2.5",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/ast-util/__test__/footnote-definition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('calcFootnoteDefinitionMap', function () {
identifier: 'bravo',
label: 'Bravo',
children: [
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
{
type: 'text',
value: 'bravo and charlie.',
Expand Down
2 changes: 1 addition & 1 deletion packages/character/src/util/entity-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function eatEntityReference(
try {
if (val === 0) val = UnicodeCodePoint.REPLACEMENT_CHARACTER
value = String.fromCodePoint(val)
} catch (error) {
} catch (_) {
value = String.fromCodePoint(UnicodeCodePoint.REPLACEMENT_CHARACTER)
}
return { nextIndex: i + 1, value }
Expand Down
2 changes: 1 addition & 1 deletion packages/character/src/util/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function createCodePointSearcher(
* But only when orderedRangeCodePoints.length * 1.5 < orderedCodePoints.length,
* the range binary search could work better (1.5 is just a hypothesis).
*
* The code point ranges are something like [left_1, right_1, left_2, right_2, ...left_n, right_n],
* The code point ranges are something like [left_1, right_1, left_2, ...left_n, right_n],
* - The good ranges: [left_1, right_0), ..., [left_i, right_i), ..., [left_n, right_n]
* - The bad ranges: [-Infinity, left_1), ..., [right_i, left_{i+1}), ..., [right_n, Infinity]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const createSinglePriorityDelimiterProcessor = (): IDelimiterProcessor =>
)

// Set internalTokens returned by processDelimiterPair.
// eslint-disable-next-line no-lone-blocks
{
for (const token of result.tokens) {
if (token._tokenizer == null) token._tokenizer = hook.name
Expand Down
3 changes: 1 addition & 2 deletions packages/core-tokenizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ along the existing nesting structure (such as the above [Blockquote][@yozora/tok
to complete the matching, and then gets a matching opportunity. In order to make the tokenizers work
with each other transparently, when designing the life cycle methods of the block-level tokenizer in
the `match-block` stage, the parsing logic of the nested structure lifted into [@yozora/core-parser
][], and use a special data structure called `PhrasingContentLine` as the actual parsing unit of a
line:
][], and use a special data structure called `PhrasingContentLine` as the actual parsing unit of a line:

```typescript
export interface PhrasingContentLine {
Expand Down
1 change: 0 additions & 1 deletion packages/core-tokenizer/src/types/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { INodeInterval } from '@yozora/character'
/**
* Make a set of properties by key `K` become optional from `T`.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
declare type IPickPartial<T extends object, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core-tokenizer/src/util/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function encodeLinkDestination(destination: string): string {
const result2 = decodeURIComponent(result)
if (result2 === result) break
result = result2
} catch (error) {
} catch (_) {
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/markup-weaver/src/MarkupWeaver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class MarkupWeaver implements IMarkupWeaver {
const isBlockLevel: boolean = weaver.isBlockLevel(node, ctx, childIndex)
if (isBlockLevel) {
dequeue(node)
throw new TypeError(`[MarkupWeaver.weave] Cannot processInline for block-level node.`)
throw new TypeError('[MarkupWeaver.weave] Cannot processInline for block-level node.')
}

let result = ''
Expand Down
3 changes: 1 addition & 2 deletions packages/parser-gfm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,7 @@ All notable changes to this project will be documented in this file. See
([ab1caca](https://github.com/yozorajs/yozora/commit/ab1caca36d2009b6487151eabf7e59361a837b05))
- :bug: [tokenizercore] fix: mistaken '>' for ']' in eatAndCollectLinkLabel
([4277f82](https://github.com/yozorajs/yozora/commit/4277f820f875eada92a4aaba06299ef7c54b38f3))
- :bug: [tokenizer-line-break, tokenizer-text] fix: remove spaces at the end of the line and
beginning
- :bug: [tokenizer-line-break, tokenizer-text] fix: remove spaces at the end of the line and beginning
([5641968](https://github.com/yozorajs/yozora/commit/5641968da7c1355141f466dd347879dccd42bbca))
- :bug: [tokenizer-list-*-item] fix: fix gfm#242, gfm#298: ListItem could contains blank lines
([edf1b58](https://github.com/yozorajs/yozora/commit/edf1b58898c3c887e5d0af717af174a9cd40ea85)),
Expand Down
1 change: 0 additions & 1 deletion scaffolds/jest-for-tokenizer/__test__/answer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-extraneous-dependencies */
import { InlineCodeTokenizerName } from '@yozora/tokenizer-inline-code'
import InlineMathTokenizer from '@yozora/tokenizer-inline-math'
import { parsers, weavers } from 'jest.setup'
Expand Down
1 change: 0 additions & 1 deletion scaffolds/jest-for-tokenizer/src/TokenizerTester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable jest/no-export, jest/valid-title */
import type { IParser } from '@yozora/core-parser'
import { BaseTester } from './BaseTester'
import type { IYozoraUseCase } from './types'
Expand Down
26 changes: 14 additions & 12 deletions scripts/gfm/classify.js → scripts/gfm/classify.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/* eslint-disable import/no-extraneous-dependencies */
const chalk = require('chalk')
const fs = require('node:fs')
const path = require('node:path')
const gfmClassifyData = require('./data.json')
import chalk from 'chalk'
import fs from 'node:fs'
import path from 'node:path'
import url from 'node:url'
import parserGfmData from './data-classify/parser-gfm.json'
import gfmClassifyData from './data.json'

const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
const rootDir = path.resolve(__dirname, '../../')

class GFMExampleClassifier {
constructor(gfmExamples) {
Expand All @@ -11,23 +16,22 @@ class GFMExampleClassifier {
}

classifyToPath(caseRootDir, groups) {
const self = this
for (const group of groups) {
const excluded = group.excluded || []
const groupDir = path.resolve(caseRootDir, group.name)
if (!fs.existsSync(groupDir)) fs.mkdirSync(groupDir, { recursive: true })
for (let i = group.start; i <= group.end; ++i) {
if (excluded.includes(i)) continue
const fileName = '#' + ('' + i).padStart(self.numberLength, '0') + '.json'
const fileName = '#' + ('' + i).padStart(this.numberLength, '0') + '.json'
const caseFilePath = path.join(groupDir, fileName)
const gfmExample = self.gfmExamples[i]
const data = self.mapGFMExampleDataToCase(gfmExample)
const gfmExample = this.gfmExamples[i]
const data = this.mapGFMExampleDataToCase(gfmExample)
const content = JSON.stringify(data, null, 2)
fs.writeFileSync(caseFilePath, content, 'utf-8')
console.log(chalk.green(`Add case ${caseFilePath}`))
}
}
return self
return this
}

mapGFMExampleDataToCase(gfmExample) {
Expand All @@ -47,10 +51,8 @@ class GFMExampleClassifier {

const classifier = new GFMExampleClassifier(gfmClassifyData)

const rootDir = path.resolve(__dirname, '../../')

// parser-gfm test cases
classifier.classifyToPath(
path.resolve(rootDir, 'scaffolds/jest-for-tokenizer/fixtures/gfm'),
require('./data-classify/parser-gfm.json'),
parserGfmData,
)
16 changes: 5 additions & 11 deletions scripts/gfm/fetch.js → scripts/gfm/fetch.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-undef */
/**
* 将 GFM 中的 example 元素解析成 JSON 数据
* @param exampleEl example 元素
*/
function parseGFMExample(exampleEl) {
export function parseGFMExample(exampleEl) {
if (exampleEl == null) return null

const exampleId = exampleEl.id || ''
Expand Down Expand Up @@ -40,7 +41,7 @@ function parseGFMExample(exampleEl) {
return result
}

function fetchGFMExamples(...exampleNos) {
export function fetchGFMExamples(...exampleNos) {
const exampleEls = exampleNos.map(exampleNo => {
const id = 'example-' + exampleNo
const elementEl = document.getElementById(id)
Expand All @@ -51,21 +52,14 @@ function fetchGFMExamples(...exampleNos) {
return JSON.stringify(result, null, 2)
}

function fetchGFMExamplesInRange(left, right = left) {
export function fetchGFMExamplesInRange(left, right = left) {
const exampleNos = []
for (let i = left; i <= right; ++i) exampleNos.push(i)
return fetchGFMExamples(...exampleNos)
}

function fetchExamplesAll() {
export function fetchExamplesAll() {
const exampleEls = document.querySelectorAll('[id^=example]')
const result = Array.from(exampleEls).map(exampleEl => parseGFMExample(exampleEl))
return JSON.stringify(result, null, 2)
}

module.exports = {
fetchExamplesAll,
fetchGFMExamples,
fetchGFMExamplesInRange,
parseGFMExample,
}
4 changes: 2 additions & 2 deletions scripts/handlebar/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ __**__foo__**__
inGfmEx: true,
isInlineTokenizer: false,
isBlockTokenizer: true,
usageDemoSourceContent: `"source contents"`,
usageDemoSourceContent: '"source contents"',
},
// fenced-code
{
Expand Down Expand Up @@ -528,7 +528,7 @@ Foo *bar*
inGfmEx: true,
isInlineTokenizer: true,
isBlockTokenizer: false,
usageDemoSourceContent: `"hello $.;'there"`,
usageDemoSourceContent: '"hello $.;\'there"',
},
// thematic-break
{
Expand Down
6 changes: 3 additions & 3 deletions scripts/handlebar/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
toTitleCase,
toTrim,
toUpperCase,
} from '@guanghechen/helper-string'
} from '@guanghechen/string'
import Handlebars from 'handlebars'
import fs from 'node:fs'
import path from 'node:path'
Expand Down Expand Up @@ -51,7 +51,7 @@ Handlebars.registerHelper('transform', (...args: any[]): string => {
const value = args[args.length - 1]
const transformFns = args
.slice(0, args.length - 2)
.map(name => transformers[name])
.map((name: string) => transformers[name as keyof typeof transformers])
.filter(fn => fn != null)
const transform = composeTextTransformers(...transformFns)
return transform(value)
Expand Down Expand Up @@ -97,7 +97,7 @@ export function renderMarkdown<D>(

const resolvedContent =
content
.replace(regex, (m, templateName): string => {
.replace(regex, (_, templateName): string => {
const result = renderTemplate(templateName, data)
return `\n\n<!-- :begin use ${templateName} -->\n\n${result}\n\n<!-- :end -->\n\n`
})
Expand Down
4 changes: 2 additions & 2 deletions scripts/nx/project.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export async function genAndWriteNxProjectJson(params, reporter) {
const { workspaceRoot, projectDir } = params
const absolutePackageDir = path.resolve(workspaceRoot, projectDir)
if (!fs.existsSync(absolutePackageDir)) {
reporter?.warn(`skipped. packageDirFromRoot is not found.`, projectDir)
reporter?.warn('skipped. packageDirFromRoot is not found.', projectDir)
return
}
if (!fs.statSync(absolutePackageDir).isDirectory()) {
reporter?.warn(`skipped. packageDirFromRoot is not a folder.`, projectDir)
reporter?.warn('skipped. packageDirFromRoot is not a folder.', projectDir)
return
}
const projectJsonPath = path.join(absolutePackageDir, 'project.json')
Expand Down
8 changes: 2 additions & 6 deletions scripts/unicode/fetch.js → scripts/unicode/fetch.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @see https://www.fileformat.info/info/unicode/category/Pd/list.htm
*/
function fetchUnicodeCharacter(tbody) {
export function fetchUnicodeCharacter(tbody) {
const trList = tbody.querySelectorAll('tr')
const items = []
for (let i = 0; i < trList.length; ++i) {
Expand All @@ -14,12 +14,8 @@ function fetchUnicodeCharacter(tbody) {

const name = nameText.trim().split(/[\s-]/g).join('_')
const value = valueText.trim().toLowerCase().replace(/^u\+/i, '0x0')
const item = ' /**\n ' + '* @see ' + url + '\n */\n ' + `${name} = ${value},`
const item = ' /**\n * @see ' + url + '\n */\n ' + name + ` = ${value},`
items.push(item)
}
return items.join('\n')
}

module.exports = {
fetchUnicodeCharacter,
}
2 changes: 1 addition & 1 deletion tokenizers/definition/src/util/link-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function eatAndCollectLinkLabel(
}

i += 1
// eslint-disable-next-line no-param-reassign

state.nodePoints.push(p)
}

Expand Down
38 changes: 19 additions & 19 deletions tokenizers/ecma-import/__test__/ecma-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ createTokenizerTesters(

describe('util', function () {
test('regex1', function () {
expect(regex1.test(`import '@yozora/parser'`)).toBe(true)
expect(regex1.test(`import "@yozora/parser"`)).toBe(true)
expect(regex1.test(`import '@yozora/parser"`)).toBe(false)
expect(regex1.test(`import "@yozora/parser'`)).toBe(false)
expect(regex1.test(`import Parser from '@yozora/parser'`)).toBe(false)
expect(regex1.test("import '@yozora/parser'")).toBe(true)
expect(regex1.test('import "@yozora/parser"')).toBe(true)
expect(regex1.test('import \'@yozora/parser"')).toBe(false)
expect(regex1.test('import "@yozora/parser\'')).toBe(false)
expect(regex1.test("import Parser from '@yozora/parser'")).toBe(false)
})

test('regex2', function () {
expect(regex2.test(`import Parser from '@yozora/parser'`)).toBe(true)
expect(regex2.test(`import Parser from "@yozora/parser"`)).toBe(true)
expect(regex2.test(`import Parser from '@yozora/parser"`)).toBe(false)
expect(regex2.test(`import Parser from "@yozora/parser'`)).toBe(false)
expect(regex2.test(`import { Parser } from "@yozora/parser'`)).toBe(false)
expect(regex2.test("import Parser from '@yozora/parser'")).toBe(true)
expect(regex2.test('import Parser from "@yozora/parser"')).toBe(true)
expect(regex2.test('import Parser from \'@yozora/parser"')).toBe(false)
expect(regex2.test('import Parser from "@yozora/parser\'')).toBe(false)
expect(regex2.test('import { Parser } from "@yozora/parser\'')).toBe(false)
})

test('regex3', function () {
expect(regex3.test(`import Parser, { a, b as c } from '@yozora/parser'`)).toBe(true)
expect(regex3.test(`import Parser, { a as c, b as d, e } from "@yozora/parser"`)).toBe(true)
expect(regex3.test(`import Parser, { a, b, c } from "@yozora/parser"`)).toBe(true)
expect(regex3.test(`import { a, b as c } from '@yozora/parser'`)).toBe(true)
expect(regex3.test(`import { a as c, b as d, e } from "@yozora/parser"`)).toBe(true)
expect(regex3.test(`import { a, b, c } from "@yozora/parser"`)).toBe(true)
expect(regex3.test(`import { a, b, c }, Parser from "@yozora/parser"`)).toBe(false)
expect(regex3.test(`import Parser from '@yozora/parser"`)).toBe(false)
expect(regex3.test(`import Parser from "@yozora/parser'`)).toBe(false)
expect(regex3.test("import Parser, { a, b as c } from '@yozora/parser'")).toBe(true)
expect(regex3.test('import Parser, { a as c, b as d, e } from "@yozora/parser"')).toBe(true)
expect(regex3.test('import Parser, { a, b, c } from "@yozora/parser"')).toBe(true)
expect(regex3.test("import { a, b as c } from '@yozora/parser'")).toBe(true)
expect(regex3.test('import { a as c, b as d, e } from "@yozora/parser"')).toBe(true)
expect(regex3.test('import { a, b, c } from "@yozora/parser"')).toBe(true)
expect(regex3.test('import { a, b, c }, Parser from "@yozora/parser"')).toBe(false)
expect(regex3.test('import Parser from \'@yozora/parser"')).toBe(false)
expect(regex3.test('import Parser from "@yozora/parser\'')).toBe(false)
})
})
Loading

0 comments on commit 224e248

Please sign in to comment.