Skip to content

Commit 5d19664

Browse files
committed
build: use dprint and oxlint
Like `u-wave-source-*`.
1 parent c947b56 commit 5d19664

4 files changed

Lines changed: 66 additions & 37 deletions

File tree

dprint.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"typescript": {
3+
"typeLiteral.separatorKind": "comma",
4+
"quoteStyle": "preferSingle",
5+
"jsx.quoteStyle": "preferDouble"
6+
},
7+
"json": {
8+
},
9+
"includes": [
10+
"src/**/*.{ts,tsx,js,jsx,cjs,mjs}",
11+
"test/**/*.{ts,tsx,js,jsx,cjs,mjs}",
12+
"./*.json"
13+
],
14+
"excludes": [
15+
"**/node_modules",
16+
"**/*-lock.json"
17+
],
18+
"plugins": [
19+
"https://plugins.dprint.dev/typescript-0.96.1.wasm",
20+
"https://plugins.dprint.dev/json-0.23.0.wasm"
21+
]
22+
}

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@
2929
"homepage": "https://github.com/u-wave/parse-chat-markup#readme",
3030
"scripts": {
3131
"prepare": "tsdown src/index.ts --format esm,cjs --dts",
32-
"lint": "eslint .",
32+
"lint": "oxlint src && dprint check",
3333
"test": "npm run tests-only && npm run lint",
3434
"tests-only": "vitest run --coverage.enabled --coverage.reporter=lcov --coverage.reporter=text --coverage.100"
3535
},
3636
"devDependencies": {
37-
"@typescript-eslint/eslint-plugin": "^8.2.0",
38-
"@typescript-eslint/parser": "^8.2.0",
3937
"@vitest/coverage-v8": "^4.1.0",
40-
"eslint": "^8.2.0",
41-
"eslint-config-airbnb-base": "^15.0.0",
42-
"eslint-plugin-import": "^2.22.0",
38+
"dprint": "^0.55.2",
39+
"oxlint": "^1.78.0",
4340
"tsdown": "^0.22.0",
4441
"typescript": "^6.0.3",
4542
"vitest": "^4.1.0"

src/index.test.js

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ describe('parseChatMarkup', () => {
144144
});
145145

146146
it('parses :emoji: that could also be italics', () => {
147-
assert.deepStrictEqual(parseChatMarkup('_it\'s :emoji_time:!', bareOptions), [
148-
'_it\'s ',
147+
assert.deepStrictEqual(parseChatMarkup("_it's :emoji_time:!", bareOptions), [
148+
"_it's ",
149149
{ type: 'emoji', name: 'emoji_time' },
150150
'!',
151151
]);
152152

153-
assert.deepStrictEqual(parseChatMarkup('_it\'s :emoji_time:!_', bareOptions), [
153+
assert.deepStrictEqual(parseChatMarkup("_it's :emoji_time:!_", bareOptions), [
154154
{
155155
type: 'italic',
156156
content: [
157-
'it\'s ',
157+
"it's ",
158158
{ type: 'emoji', name: 'emoji_time' },
159159
'!',
160160
],
@@ -208,29 +208,38 @@ describe('parseChatMarkup', () => {
208208
});
209209

210210
it('parses @-mentions with punctuation in them', () => {
211-
assert.deepStrictEqual(parseChatMarkup('@user[AFK] hello!', {
212-
mentions: ['user[AFK]'],
213-
}), [
214-
{ type: 'mention', mention: 'user[afk]', raw: 'user[AFK]' },
215-
' hello!',
216-
]);
217-
218-
assert.deepStrictEqual(parseChatMarkup('hello @user[AFK]', {
219-
mentions: ['user[AFK]'],
220-
}), [
221-
'hello ',
222-
{ type: 'mention', mention: 'user[afk]', raw: 'user[AFK]' },
223-
]);
211+
assert.deepStrictEqual(
212+
parseChatMarkup('@user[AFK] hello!', {
213+
mentions: ['user[AFK]'],
214+
}),
215+
[
216+
{ type: 'mention', mention: 'user[afk]', raw: 'user[AFK]' },
217+
' hello!',
218+
],
219+
);
220+
221+
assert.deepStrictEqual(
222+
parseChatMarkup('hello @user[AFK]', {
223+
mentions: ['user[AFK]'],
224+
}),
225+
[
226+
'hello ',
227+
{ type: 'mention', mention: 'user[afk]', raw: 'user[AFK]' },
228+
],
229+
);
224230
});
225231

226232
it('parses @-mentions with no clear word boundary', () => {
227-
assert.deepStrictEqual(parseChatMarkup('hello @ReAnna!!!', {
228-
mentions: ['ReAnna!!'],
229-
}), [
230-
'hello ',
231-
{ type: 'mention', mention: 'reanna!!', raw: 'ReAnna!!' },
232-
'!',
233-
]);
233+
assert.deepStrictEqual(
234+
parseChatMarkup('hello @ReAnna!!!', {
235+
mentions: ['ReAnna!!'],
236+
}),
237+
[
238+
'hello ',
239+
{ type: 'mention', mention: 'reanna!!', raw: 'ReAnna!!' },
240+
'!',
241+
],
242+
);
234243
});
235244
});
236245
});

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,16 @@ function createToken(type: TokenType, text: string, raw: string = text): Token {
139139
* Sort users by username length. Longest usernames first.
140140
*/
141141
const sortMentions = memoize((mentions: string[]): string[] => (
142-
mentions.slice().sort((a, b) => b.length - a.length)));
143-
144-
const makeMentionRegExp = memoize((mentions: string[]): RegExp => new RegExp(
145-
`^(${
146-
mentions.map((mention) => escapeStringRegExp(mention)).join('|')
147-
})(?:\\b|\\s|\\W|$)`,
148-
'i',
142+
mentions.slice().sort((a, b) => b.length - a.length)
149143
));
150144

145+
const makeMentionRegExp = memoize((mentions: string[]): RegExp =>
146+
new RegExp(
147+
`^(${mentions.map((mention) => escapeStringRegExp(mention)).join('|')})(?:\\b|\\s|\\W|$)`,
148+
'i',
149+
)
150+
);
151+
151152
/**
152153
* Case-insensitively get the correct emoji name from the possible emoji for an
153154
* input string.

0 commit comments

Comments
 (0)