Skip to content

Commit

Permalink
Small adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 5, 2024
1 parent 7a5f0a8 commit 32d78f7
Show file tree
Hide file tree
Showing 6 changed files with 753 additions and 1,987 deletions.
52 changes: 17 additions & 35 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
import prettier from 'eslint-plugin-prettier'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import tseslint from 'typescript-eslint'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends(
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
),
export default tseslint.config(
{
ignores: ['esm/**/*', 'dist/**/*', '*.js', '*.mjs', 'example/*'],
},
{
plugins: {
prettier,
'@typescript-eslint': typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
project: './tsconfig.lint.json',
project: ['./tsconfig.lint.json'],
tsconfigRootDir: import.meta.dirname,
},
},

},
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylisticTypeChecked,
...tseslint.configs.strictTypeChecked,
eslintPluginUnicorn.configs['flat/recommended'],
{
rules: {
'no-underscore-dangle': 0,
curly: 'error',
Expand All @@ -52,4 +34,4 @@ export default [
semi: ['error', 'never'],
},
},
]
)
23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,30 @@
"node": ">=10"
},
"scripts": {
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
"prebuild": "rimraf dist esm",
"build:esm": "tsc --target es2018 --outDir esm --module es2020",
"build:es5": "tsc --target es5 --outDir dist --module commonjs",
"build": "npm run build:esm && npm run build:es5",
"preversion": "npm run lint && npm test && npm run build",
"preversion": "npm run lint && npm test run && npm run build",
"postversion": "git push --follow-tags",
"test": "jest"
"test": "vitest"
},
"name": "@gmod/trix",
"author": "Matt Morgan",
"repository": "GMOD/trix-js",
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
"@types/jest": "^29.2.4",
"@types/node": "^20.14.11",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-unicorn": "^54.0.0",
"eslint-plugin-unicorn": "^55.0.0",
"generic-filehandle": "^3.0.0",
"jest": "^29.3.1",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"ts-jest": "^29.0.3",
"typescript": "^5.5.3"
"typescript": "^5.5.3",
"typescript-eslint": "^8.4.0",
"vitest": "^2.0.5"
},
"dependencies": {},
"publishConfig": {
Expand Down
44 changes: 23 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class Trix {

let { end, buffer } = res
let done = false
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (!done) {
let foundSomething = false
const str = buffer.toString()
Expand All @@ -56,26 +57,27 @@ export default class Trix {
.split('\n')
.filter(f => !!f)

const hits = lines

.filter(line => {
const word = line.split(' ')[0]
const match = word.startsWith(searchWord)
if (!foundSomething && match) {
foundSomething = true
}

// we are done scanning if we are lexicographically greater than the
// search string
if (word.slice(0, searchWord.length) > searchWord) {
done = true
}
return match
})
.flatMap(line => {
const [term, ...parts] = line.split(' ')
return parts.map(elt => [term, elt.split(',')[0]])
}) as [string, string][]
const hits2 = [] as string[]
for (const line of lines) {
const word = line.split(' ')[0]
const match = word.startsWith(searchWord)
if (!foundSomething && match) {
foundSomething = true
}

// we are done scanning if we are lexicographically greater than the
// search string
if (word.slice(0, searchWord.length) > searchWord) {
done = true
}
if (match) {
hits2.push(line)
}
}
const hits = hits2.flatMap(line => {
const [term, ...parts] = line.split(' ')
return parts.map(elt => [term, elt.split(',')[0]] as [string, string])
})

// if we are not done, and we haven't filled up maxResults with hits yet,
// then refetch
Expand Down Expand Up @@ -122,7 +124,7 @@ export default class Trix {
const prefix = line.slice(0, p)
const posStr = line.slice(p)
const pos = Number.parseInt(posStr, 16)
return [prefix, pos] as [string, number]
return [prefix, pos] as const
})
}

Expand Down
Loading

0 comments on commit 32d78f7

Please sign in to comment.