Skip to content

Commit

Permalink
fix: resolve eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
niieani committed Dec 18, 2020
1 parent fc0c66c commit 7a9e9f6
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 14 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = {
'jest/no-jasmine-globals': 'error',
'jest/no-jest-import': 'error',
'jest/no-test-prefixes': 'error',
'jest/no-test-callback': 'error',
'jest/no-test-return-statement': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/prefer-spy-on': 'error',
Expand Down
6 changes: 4 additions & 2 deletions lib/hashids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export default class Hashids {

if (uniqueAlphabet.length < minAlphabetLength) {
throw new Error(
`Hashids: alphabet must contain at least ${minAlphabetLength} unique characters, provided: ${uniqueAlphabet}`,
`Hashids: alphabet must contain at least ${minAlphabetLength} unique characters, provided: ${uniqueAlphabet.join(
'',
)}`,
)
}

Expand Down Expand Up @@ -164,7 +166,7 @@ export default class Hashids {
return this.encode(numbers)
}

public decodeHex(id: string) {
public decodeHex(id: string): string {
return this.decode(id)
.map((number) => number.toString(16).slice(1))
.join('')
Expand Down
8 changes: 4 additions & 4 deletions tests/bad-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('bad input', () => {

test(`should throw an error when alphabet not a string`, () => {
expect(() => {
// @ts-ignore
// @ts-expect-error wrong output
void new Hashids('', 0, 7)
}).toThrow(TypeError)
})
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('bad input', () => {
})

test(`should return an empty string when encoding a null`, () => {
// @ts-ignore
// @ts-expect-error wrong output
const id = hashids.encode(null)
expect(id).toEqual('')
})
Expand All @@ -59,7 +59,7 @@ describe('bad input', () => {
})

test(`should return an empty string when encoding an undefined`, () => {
// @ts-ignore
// @ts-expect-error wrong output
const id = hashids.encode(undefined)
expect(id).toEqual('')
})
Expand All @@ -70,7 +70,7 @@ describe('bad input', () => {
})

test(`should return an empty array when decoding nothing`, () => {
// @ts-ignore
// @ts-expect-error wrong output
const numbers = hashids.decode()
expect(numbers).toEqual([])
})
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable no-console */
import benchmark from 'nodemark'
import Hashids from '../lib/hashids'
Expand Down
3 changes: 1 addition & 2 deletions tests/bigint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const _BigInt = typeof BigInt === 'function' ? BigInt : undefined

describe('BigInt environment', () => {
beforeAll(() => {
// @ts-ignore
// @ts-expect-error wrong output
delete global.BigInt
})

afterAll(() => {
// @ts-ignore
if (_BigInt) global.BigInt = _BigInt
})

Expand Down
6 changes: 5 additions & 1 deletion tests/custom-params-hex.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import Hashids from '../lib/hashids'

const minLength = 30
Expand Down Expand Up @@ -27,7 +29,9 @@ describe.each([
],
// bigint format:
...(typeof BigInt === 'function'
? require('./bigint-test-cases').customParamsHex
? (require('./bigint-test-cases').customParamsHex as Array<
[string, string]
>)
: []),
] as [string, string | bigint][])(
'encodeHex/decodeHex using default params',
Expand Down
4 changes: 4 additions & 0 deletions tests/custom-params.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Hashids from '../lib/hashids'

const minLength = 30
Expand Down
3 changes: 3 additions & 0 deletions tests/custom-salt.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Hashids from '../lib/hashids'

describe('custom salt', () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/default-params.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Hashids from '../lib/hashids'

const hashids = new Hashids()
Expand Down
8 changes: 5 additions & 3 deletions tests/requiring.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// @ts-ignore
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// @ts-expect-error wrong output
import ImportedHashids from '../cjs'

describe('requiring', () => {
test('via node', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Hashids = require('../cjs')
const Hashids = require('../cjs') as typeof import('../lib/hashids').default
expect(typeof Hashids).toBe('function')
const instance = new Hashids('Not Real', 5, 'ABCDEFGHJKMNPQRTWXY234689')
expect(instance).toBeInstanceOf(Hashids)
})

test('via babel default import', () => {
expect(typeof ImportedHashids).toBe('function')
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const instance = new ImportedHashids(
'Not Real',
5,
Expand Down

0 comments on commit 7a9e9f6

Please sign in to comment.