Skip to content

Commit 347f2de

Browse files
committed
Linting
1 parent 5211671 commit 347f2de

15 files changed

+52
-66
lines changed

rollup.config.js

+3-19
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,10 @@ import typescript from 'rollup-plugin-typescript2'
66
import pkg from './package.json'
77
import { terser } from 'rollup-plugin-terser'
88

9-
function pascalCase(myStr) {
10-
return toUpperCase(dashToCamelCase(myStr))
11-
}
12-
13-
function normalizePackageName(rawPackageName) {
14-
const scopeEnd = rawPackageName.indexOf('/') + 1
15-
16-
return rawPackageName.substring(scopeEnd)
17-
}
18-
199
function getOutputFileName(fileName, isProd = false) {
2010
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName
2111
}
2212

23-
function toUpperCase(myStr) {
24-
return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`
25-
}
26-
27-
function dashToCamelCase(myStr) {
28-
return myStr.replace(/-([a-z])/g, (g) => g[1].toUpperCase())
29-
}
30-
3113
const env = process.env.NODE_ENV || 'development'
3214
const LIB_NAME = 'MeiliSearch'
3315
const ROOT = resolve(__dirname, '.')
@@ -36,7 +18,9 @@ const PLUGINS = [
3618
typescript({
3719
useTsconfigDeclarationDir: true,
3820
tsconfigOverride: {
39-
exclude: ['tests'],
21+
allowJs: false,
22+
includes: ['src'],
23+
exclude: ['tests', 'examples', '*.js', 'scripts'],
4024
esModuleInterop: true,
4125
},
4226
}),

src/meilisearch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class MeiliSearch extends MeiliAxiosWrapper
101101
async isHealthy(): Promise<boolean> {
102102
const url = '/health'
103103

104-
return await this.get(url).then((_) => true)
104+
return await this.get(url).then(() => true)
105105
}
106106

107107
/**

src/types.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@ export interface AddDocumentParams {
5151
primaryKey?: string
5252
}
5353

54-
export type FacetFilter = (string | string[])[]
54+
export type FacetFilter = Array<string | string[]>
5555

5656
export interface SearchParams<T> {
5757
offset?: number
5858
limit?: number
59-
attributesToRetrieve?: Extract<keyof T, string>[] | Extract<keyof T, string>
59+
attributesToRetrieve?:
60+
| Array<Extract<keyof T, string>>
61+
| Extract<keyof T, string>
6062
attributesToCrop?:
61-
| (Extract<keyof T, string> | '*')[]
63+
| Array<Extract<keyof T, string> | '*'>
6264
| (Extract<keyof T, string> | '*')
6365
cropLength?: number
6466
attributesToHighlight?:
65-
| (Extract<keyof T, string> | '*')[]
67+
| Array<Extract<keyof T, string> | '*'>
6668
| (Extract<keyof T, string> | '*')
6769
filters?: string
6870
facetFilters?: string | FacetFilter | FacetFilter[]
@@ -114,7 +116,9 @@ export interface FieldFrequency {
114116
export interface GetDocumentsParams<T> {
115117
offset?: number
116118
limit?: number
117-
attributesToRetrieve?: Extract<keyof T, string>[] | Extract<keyof T, string>
119+
attributesToRetrieve?:
120+
| Array<Extract<keyof T, string>>
121+
| Extract<keyof T, string>
118122
}
119123

120124
export type GetDocumentsResponse<
@@ -131,7 +135,7 @@ export type GetDocumentsResponse<
131135
: Array<Document<T>>
132136

133137
export type DocumentLike = { [Key in string]?: DocumentField }
134-
export interface DocumentArray extends Array<DocumentField> {}
138+
export type DocumentArray = DocumentField[]
135139
export type DocumentField =
136140
| string
137141
| number

tests/accept_new_fields_tests.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe.each([
3131
await client
3232
.getIndex(index.uid)
3333
.getAcceptNewFields()
34-
.then((response: Boolean) => {
34+
.then((response: boolean) => {
3535
expect(response).toEqual(true)
3636
})
3737
})
@@ -47,7 +47,7 @@ describe.each([
4747
await client
4848
.getIndex(index.uid)
4949
.getAcceptNewFields()
50-
.then((response: Boolean) => {
50+
.then((response: boolean) => {
5151
expect(response).toEqual(false)
5252
})
5353
})

tests/attributes_for_faceting_tests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ describe.each([
4949
await client
5050
.getIndex(index.uid)
5151
.getAttributesForFaceting()
52-
.then((response: String[]) => {
52+
.then((response: string[]) => {
5353
expect(response.sort()).toEqual([])
5454
})
5555
})
5656
test(`${permission} key: Update attributes for filtering`, async () => {
57-
const new_attributes_for_faceting = ['genre']
57+
const newAttributesForFaceting = ['genre']
5858
const { updateId } = await client
5959
.getIndex(index.uid)
60-
.updateAttributesForFaceting(new_attributes_for_faceting)
60+
.updateAttributesForFaceting(newAttributesForFaceting)
6161
.then((response: Types.EnqueuedUpdate) => {
6262
expect(response).toHaveProperty('updateId', expect.any(Number))
6363
return response
@@ -66,8 +66,8 @@ describe.each([
6666
await client
6767
.getIndex(index.uid)
6868
.getAttributesForFaceting()
69-
.then((response: String[]) => {
70-
expect(response).toEqual(new_attributes_for_faceting)
69+
.then((response: string[]) => {
70+
expect(response).toEqual(newAttributesForFaceting)
7171
})
7272
})
7373
test(`${permission} key: Reset attributes for filtering`, async () => {
@@ -82,7 +82,7 @@ describe.each([
8282
await client
8383
.getIndex(index.uid)
8484
.getAttributesForFaceting()
85-
.then((response: String[]) => {
85+
.then((response: string[]) => {
8686
expect(response.sort()).toEqual([])
8787
})
8888
})

tests/client_tests.ts

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ describe.each([
146146
})
147147

148148
test(`${permission} key: create index with missing uid should fail`, async () => {
149-
// @ts-ignore
150149
await expect(client.createIndex(null)).rejects.toThrowError(
151150
`Index creation must have an uid`
152151
)

tests/displayed_attributes_tests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ describe.each([
4949
await client
5050
.getIndex(index.uid)
5151
.getDisplayedAttributes()
52-
.then((response: String[]) => {
52+
.then((response: string[]) => {
5353
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
5454
})
5555
})
5656
test(`${permission} key: Update displayed attributes`, async () => {
57-
const new_da = ['title']
57+
const newDisplayedAttribute = ['title']
5858
const { updateId } = await client
5959
.getIndex(index.uid)
60-
.updateDisplayedAttributes(new_da)
60+
.updateDisplayedAttributes(newDisplayedAttribute)
6161
.then((response: Types.EnqueuedUpdate) => {
6262
expect(response).toHaveProperty('updateId', expect.any(Number))
6363
return response
@@ -66,8 +66,8 @@ describe.each([
6666
await client
6767
.getIndex(index.uid)
6868
.getDisplayedAttributes()
69-
.then((response: String[]) => {
70-
expect(response).toEqual(new_da)
69+
.then((response: string[]) => {
70+
expect(response).toEqual(newDisplayedAttribute)
7171
})
7272
})
7373
test(`${permission} key: Reset displayed attributes`, async () => {
@@ -82,7 +82,7 @@ describe.each([
8282
await client
8383
.getIndex(index.uid)
8484
.getDisplayedAttributes()
85-
.then((response: String[]) => {
85+
.then((response: string[]) => {
8686
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
8787
})
8888
})

tests/distinct_attribute_tests.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ describe.each([
5454
})
5555
})
5656
test(`${permission} key: Update distinct attribute`, async () => {
57-
const new_da = 'title'
57+
const newDistinctAttribute = 'title'
5858
const { updateId } = await client
5959
.getIndex(index.uid)
60-
.updateDistinctAttribute(new_da)
60+
.updateDistinctAttribute(newDistinctAttribute)
6161
.then((response: Types.EnqueuedUpdate) => {
6262
expect(response).toHaveProperty('updateId', expect.any(Number))
6363
return response
@@ -67,7 +67,7 @@ describe.each([
6767
.getIndex(index.uid)
6868
.getDistinctAttribute()
6969
.then((response: string | null) => {
70-
expect(response).toEqual(new_da)
70+
expect(response).toEqual(newDistinctAttribute)
7171
})
7272
})
7373
test(`${permission} key: Reset distinct attribute`, async () => {

tests/get_or_create_tests.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as Types from '../src/types'
21
import {
32
clearAllIndexes,
43
config,

tests/meilisearch-test-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const anonymousClient = new MeiliSearch({
2929
host: HOST,
3030
})
3131

32-
const clearAllIndexes = async (config: Types.Config) => {
32+
const clearAllIndexes = async (config: Types.Config): Promise<void> => {
3333
const client = new MeiliSearch(config)
3434
const indexes = await client
3535
.listIndexes()

tests/ranking_rules_tests.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ describe.each([
6363
})
6464
})
6565
test(`${permission} key: Update ranking rules`, async () => {
66-
const new_rr = ['asc(title)', 'typo', 'desc(description)']
66+
const newRankingRules = ['asc(title)', 'typo', 'desc(description)']
6767
const { updateId } = await client
6868
.getIndex(index.uid)
69-
.updateRankingRules(new_rr)
69+
.updateRankingRules(newRankingRules)
7070
.then((response: Types.EnqueuedUpdate) => {
7171
expect(response).toHaveProperty('updateId', expect.any(Number))
7272
return response
@@ -76,7 +76,7 @@ describe.each([
7676
.getIndex(index.uid)
7777
.getRankingRules()
7878
.then((response: string[]) => {
79-
expect(response).toEqual(new_rr)
79+
expect(response).toEqual(newRankingRules)
8080
})
8181
})
8282
test(`${permission} key: Reset ranking rules`, async () => {

tests/search_tests.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ describe.each([
7070
await clearAllIndexes(config)
7171
await masterClient.createIndex(index.uid)
7272
await masterClient.createIndex(emptyIndex.uid)
73-
const new_attributes_for_faceting = ['genre']
73+
const newAttributesForFaceting = ['genre']
7474
const { updateId: settingUpdateId } = await masterClient
7575
.getIndex(index.uid)
76-
.updateAttributesForFaceting(new_attributes_for_faceting)
76+
.updateAttributesForFaceting(newAttributesForFaceting)
7777
.then((response: Types.EnqueuedUpdate) => {
7878
expect(response).toHaveProperty('updateId', expect.any(Number))
7979
return response

tests/searchable_attributes_tests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ describe.each([
4949
await client
5050
.getIndex(index.uid)
5151
.getSearchableAttributes()
52-
.then((response: String[]) => {
52+
.then((response: string[]) => {
5353
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
5454
})
5555
})
5656
test(`${permission} key: Update searchable attributes`, async () => {
57-
const new_da = ['title']
57+
const newSearchableAttributes = ['title']
5858
const { updateId } = await client
5959
.getIndex(index.uid)
60-
.updateSearchableAttributes(new_da)
60+
.updateSearchableAttributes(newSearchableAttributes)
6161
.then((response: Types.EnqueuedUpdate) => {
6262
expect(response).toHaveProperty('updateId', expect.any(Number))
6363
return response
@@ -66,8 +66,8 @@ describe.each([
6666
await client
6767
.getIndex(index.uid)
6868
.getSearchableAttributes()
69-
.then((response: String[]) => {
70-
expect(response).toEqual(new_da)
69+
.then((response: string[]) => {
70+
expect(response).toEqual(newSearchableAttributes)
7171
})
7272
})
7373
test(`${permission} key: Reset searchable attributes`, async () => {
@@ -82,7 +82,7 @@ describe.each([
8282
await client
8383
.getIndex(index.uid)
8484
.getSearchableAttributes()
85-
.then((response: String[]) => {
85+
.then((response: string[]) => {
8686
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
8787
})
8888
})

tests/stop_words_tests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ describe.each([
4949
await client
5050
.getIndex(index.uid)
5151
.getStopWords()
52-
.then((response: String[]) => {
52+
.then((response: string[]) => {
5353
expect(response).toEqual([])
5454
})
5555
})
5656
test(`${permission} key: Update stop words`, async () => {
57-
const new_sw = ['the']
57+
const newStopWords = ['the']
5858
const { updateId } = await client
5959
.getIndex(index.uid)
60-
.updateStopWords(new_sw)
60+
.updateStopWords(newStopWords)
6161
.then((response: Types.EnqueuedUpdate) => {
6262
expect(response).toHaveProperty('updateId', expect.any(Number))
6363
return response
@@ -66,8 +66,8 @@ describe.each([
6666
await client
6767
.getIndex(index.uid)
6868
.getStopWords()
69-
.then((response: String[]) => {
70-
expect(response).toEqual(new_sw)
69+
.then((response: string[]) => {
70+
expect(response).toEqual(newStopWords)
7171
})
7272
})
7373
test(`${permission} key: Reset stop words`, async () => {
@@ -82,7 +82,7 @@ describe.each([
8282
await client
8383
.getIndex(index.uid)
8484
.getStopWords()
85-
.then((response: String[]) => {
85+
.then((response: string[]) => {
8686
expect(response).toEqual([])
8787
})
8888
})

tests/synonyms_tests.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ describe.each([
5454
})
5555
})
5656
test(`${permission} key: Update synonyms`, async () => {
57-
const new_sy = {
57+
const newSynonyms = {
5858
hp: ['harry potter'],
5959
}
6060
const { updateId } = await client
6161
.getIndex(index.uid)
62-
.updateSynonyms(new_sy)
62+
.updateSynonyms(newSynonyms)
6363
.then((response: Types.EnqueuedUpdate) => {
6464
expect(response).toHaveProperty('updateId', expect.any(Number))
6565
return response
@@ -69,7 +69,7 @@ describe.each([
6969
.getIndex(index.uid)
7070
.getSynonyms()
7171
.then((response: object) => {
72-
expect(response).toEqual(new_sy)
72+
expect(response).toEqual(newSynonyms)
7373
})
7474
})
7575
test(`${permission} key: Reset synonyms`, async () => {

0 commit comments

Comments
 (0)