Skip to content

Commit 9fa5774

Browse files
committed
chore: eslint fixes
1 parent 4f7719e commit 9fa5774

File tree

4 files changed

+63
-63
lines changed

4 files changed

+63
-63
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ jobs:
3737

3838
- name: Test
3939
run: |-
40-
npm run test:ci
4140
npm run build
41+
npm run test:ci
4242
4343
# Publish
4444
- name: Publish

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build": "tsc --project tsconfig.build.json",
1010
"test": "jest --config jest.config.ts --coverage",
1111
"test:ci": "npm run lint && npm run test -- --no-cache",
12+
"all": "npm run lint && npm run build && npm run test",
1213
"prepack": "npm run build"
1314
},
1415
"repository": {

src/properties.spec.ts

+36-49
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as fs from 'node:fs/promises'
2+
23
import properties from '.'
34

45
describe('parse', () => {
56
it('should parse all lines', () => {
67
// Data
7-
const sample = 'registry=https://abcd\n#foo bar\r\n@scope:test=avx\rextra\r\n'
8+
const sample =
9+
'registry=https://abcd\n#foo bar\r\n@scope:test=avx\rextra\r\n'
810

911
// Test
1012
const result = properties.parse(sample)
@@ -108,21 +110,17 @@ describe('data access', () => {
108110
expect(result).toBe(expected)
109111
})
110112

111-
it.each([
112-
['foo6'],
113-
['foo7']
114-
])('should not get commented property "%s"', (key) => {
115-
const result = properties.get(sample, key)
116-
expect(result).toBeUndefined()
117-
})
113+
it.each([['foo6'], ['foo7']])(
114+
'should not get commented property "%s"',
115+
key => {
116+
const result = properties.get(sample, key)
117+
expect(result).toBeUndefined()
118+
}
119+
)
118120

119121
it('should return last value of duplicate key', () => {
120122
const config: properties.Properties = {
121-
lines: [
122-
'key1=foo1',
123-
'key2=foo2',
124-
'key1=foo3'
125-
]
123+
lines: ['key1=foo1', 'key2=foo2', 'key1=foo3']
126124
}
127125

128126
const result = properties.get(config, 'key1')
@@ -137,16 +135,16 @@ describe('data access', () => {
137135
expect(() => properties.get(config, 'foo')).toThrowError()
138136
})
139137

140-
it.each([
141-
['foo=bar\\u23a'],
142-
['foo=bar\\u23ax5']
143-
])('should throw on invalid unicode sequence in value %s', (line) => {
144-
const config: properties.Properties = {
145-
lines: [line]
146-
}
138+
it.each([['foo=bar\\u23a'], ['foo=bar\\u23ax5']])(
139+
'should throw on invalid unicode sequence in value %s',
140+
line => {
141+
const config: properties.Properties = {
142+
lines: [line]
143+
}
147144

148-
expect(() => properties.get(config, 'foo')).toThrowError()
149-
})
145+
expect(() => properties.get(config, 'foo')).toThrowError()
146+
}
147+
)
150148

151149
it.each([
152150
['foo=bar', 'bar'],
@@ -259,33 +257,20 @@ describe('data access', () => {
259257

260258
it('should use custom separator', () => {
261259
const config: properties.Properties = {
262-
lines: [
263-
'key1=foo1',
264-
'key2=foo2'
265-
]
260+
lines: ['key1=foo1', 'key2=foo2']
266261
}
267262

268263
properties.set(config, 'key1', 'test', {separator: ': '})
269-
expect(config.lines).toEqual([
270-
'key1: test',
271-
'key2=foo2'
272-
])
264+
expect(config.lines).toEqual(['key1: test', 'key2=foo2'])
273265
})
274266

275267
it('should remove duplicate keys on set', () => {
276268
const config: properties.Properties = {
277-
lines: [
278-
'key1=foo1',
279-
'key2=foo2',
280-
'key1=foo3'
281-
]
269+
lines: ['key1=foo1', 'key2=foo2', 'key1=foo3']
282270
}
283271

284272
properties.set(config, 'key1', 'test')
285-
expect(config.lines).toEqual([
286-
'key1=test',
287-
'key2=foo2'
288-
])
273+
expect(config.lines).toEqual(['key1=test', 'key2=foo2'])
289274
})
290275
})
291276

@@ -308,11 +293,7 @@ describe('data access', () => {
308293

309294
it('should remove all duplicate keys with remove', () => {
310295
const config: properties.Properties = {
311-
lines: [
312-
'key1=foo1',
313-
'key2=foo2',
314-
'key1=foo3'
315-
]
296+
lines: ['key1=foo1', 'key2=foo2', 'key1=foo3']
316297
}
317298

318299
properties.remove(config, 'key1')
@@ -381,7 +362,10 @@ describe('data access', () => {
381362
})
382363

383364
it('should parse test file', async () => {
384-
const contents = await fs.readFile(require.resolve('../fixtures/test-all.properties'), 'utf-8')
365+
const contents = await fs.readFile(
366+
require.resolve('../fixtures/test-all.properties'),
367+
'utf-8'
368+
)
385369

386370
// Parse
387371
const result = properties.toObject(properties.parse(contents))
@@ -397,19 +381,22 @@ describe('data access', () => {
397381
'evenLikeThis\\': '',
398382
hello: 'hello',
399383
helloInJapanese: 'こんにちは',
400-
'こんにちは': 'hello',
384+
こんにちは: 'hello',
401385
keyWithBackslashes: 'This has random backslashes',
402-
'keyWithDelimiters:= ': 'This is the value for the key "keyWithDelimiters:= "',
386+
'keyWithDelimiters:= ':
387+
'This is the value for the key "keyWithDelimiters:= "',
403388
'keyWitheven\\': 'this colon is not escaped',
404389
language: 'English',
405390
multiline: 'This line continues on 3 lines',
406391
multilineKey: 'this is a multiline key',
407-
noWhiteSpace: 'The key will be "noWhiteSpace" without any whitespace. ',
392+
noWhiteSpace:
393+
'The key will be "noWhiteSpace" without any whitespace. ',
408394
oddKey: 'This is line one and\\# This is line two',
409395
orLikeThis: '',
410396
path: 'c:\\wiki\\templates',
411397
topic: '.properties file',
412-
valueWithEscapes: 'This is a newline\n, a carriage return\r, a tab\t and a formfeed\f.',
398+
valueWithEscapes:
399+
'This is a newline\n, a carriage return\r, a tab\t and a formfeed\f.',
413400
website: 'https://en.wikipedia.org/',
414401
welcome: 'Welcome to Wikipedia! '
415402
})

src/properties.ts

+25-13
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export const remove = (config: Properties, key: string): void =>
199199
*
200200
* @param lines Lines to iterate over.
201201
*/
202-
function* chars(lines: string[]): Generator<{char: string, line: number}> {
202+
function* chars(lines: string[]): Generator<{char: string; line: number}> {
203203
for (let i = 0; i < lines.length; i++) {
204204
const line = lines[i]
205205
for (const char of line) {
@@ -225,16 +225,23 @@ function* listPairs(lines: string[]): Generator<{
225225
value: string
226226
}> {
227227
const newState = (): {
228-
state: State,
229-
start: number,
230-
key: string,
231-
sep: string,
232-
value: string,
233-
skipSpace: boolean,
234-
escapedNext: boolean,
228+
state: State
229+
start: number
230+
key: string
231+
sep: string
232+
value: string
233+
skipSpace: boolean
234+
escapedNext: boolean
235235
unicode?: string
236-
} =>
237-
({state: State.START, start: -1, key: '', sep: '', value: '', skipSpace: true, escapedNext: false})
236+
} => ({
237+
state: State.START,
238+
start: -1,
239+
key: '',
240+
sep: '',
241+
value: '',
242+
skipSpace: true,
243+
escapedNext: false
244+
})
238245

239246
let state = newState()
240247

@@ -455,7 +462,10 @@ const parseUnicode = (sequence: string, line: number): string => {
455462
* @param escapeUnicode Escape unicode chars (below 0x0020 and above 0x007e). Default is true.
456463
* @return Escaped string.
457464
*/
458-
export const escapeKey = (unescapedKey: string, escapeUnicode = true): string => {
465+
export const escapeKey = (
466+
unescapedKey: string,
467+
escapeUnicode = true
468+
): string => {
459469
return escape(unescapedKey, true, escapeUnicode)
460470
}
461471

@@ -466,7 +476,10 @@ export const escapeKey = (unescapedKey: string, escapeUnicode = true): string =>
466476
* @param escapeUnicode Escape unicode chars (below 0x0020 and above 0x007e). Default is true.
467477
* @return Escaped string.
468478
*/
469-
export const escapeValue = (unescapedValue: string, escapeUnicode = true): string => {
479+
export const escapeValue = (
480+
unescapedValue: string,
481+
escapeUnicode = true
482+
): string => {
470483
return escape(unescapedValue, false, escapeUnicode)
471484
}
472485

@@ -485,7 +498,6 @@ const escape = (
485498
): string => {
486499
const result: string[] = []
487500

488-
// eslint-disable-next-line unicorn/no-for-loop
489501
for (let index = 0; index < unescapedContent.length; index++) {
490502
const char = unescapedContent[index]
491503
switch (char) {

0 commit comments

Comments
 (0)