Skip to content

Commit

Permalink
Added eslint prettier plugin for simplification
Browse files Browse the repository at this point in the history
Linting

Remove tests as it is not possible with typescript to keep it
  • Loading branch information
bidoubiwa committed Jul 27, 2020
1 parent ae75807 commit bdc5fac
Show file tree
Hide file tree
Showing 20 changed files with 227 additions and 202 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
examples
scripts
13 changes: 10 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ module.exports = {
env: {
browser: true,
es6: true,
'jest/globals': true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'standard-with-typescript',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended',
'prettier/@typescript-eslint',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json'],
ecmaVersion: 2018,
project: ['tsconfig.eslint.json'],
sourceType: 'module',
projectFolderIgnoreList: ['dist'],
},
plugins: ['jsdoc', '@typescript-eslint'],
plugins: ['jsdoc', '@typescript-eslint', 'prettier', 'jest'],
rules: {
'no-dupe-class-members': 'off', // Off due to conflict with typescript overload functions
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
'@typescript-eslint/return-await': 'off',
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
"test:coverage": "yarn test --coverage",
"test:ci": "yarn test --ci",
"size": "node scripts/file-size ./dist/bundles/meilisearch.cjs.min.js ./dist/bundles/meilisearch.esm.min.js ./dist/bundles/meilisearch.browser.min.js",
"style": "yarn format && yarn lint",
"style:fix": "yarn format:fix && yarn lint:fix",
"prettier": "prettier \"**/*.{ts,tsx,js,jsx,css,scss,sass,less,md}\"",
"format": "yarn prettier --debug-check",
"format:fix": "yarn prettier --write",
"lint": "eslint '{src,types}/**/*.{ts,js}'",
"lint:fix": "yarn lint --fix",
"style": "yarn lint",
"style:fix": "yarn lint:fix",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
"typingsheader": "node scripts/build.js"
},
"lint-staged": {
Expand All @@ -67,11 +64,14 @@
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
"brotli-size": "^4.0.0",
"eslint": "6",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard-with-typescript": "^17.0.0",
"eslint-plugin-import": "2",
"eslint-plugin-jest": "^23.18.0",
"eslint-plugin-jsdoc": "^30.0.0",
"eslint-plugin-node": "11",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "4",
"eslint-plugin-standard": "4",
"gzip-size": "^5.1.1",
Expand Down
22 changes: 3 additions & 19 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,10 @@ import typescript from 'rollup-plugin-typescript2'
import pkg from './package.json'
import { terser } from 'rollup-plugin-terser'

function pascalCase(myStr) {
return toUpperCase(dashToCamelCase(myStr))
}

function normalizePackageName(rawPackageName) {
const scopeEnd = rawPackageName.indexOf('/') + 1

return rawPackageName.substring(scopeEnd)
}

function getOutputFileName(fileName, isProd = false) {
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName
}

function toUpperCase(myStr) {
return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`
}

function dashToCamelCase(myStr) {
return myStr.replace(/-([a-z])/g, (g) => g[1].toUpperCase())
}

const env = process.env.NODE_ENV || 'development'
const LIB_NAME = 'MeiliSearch'
const ROOT = resolve(__dirname, '.')
Expand All @@ -36,7 +18,9 @@ const PLUGINS = [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
exclude: ['tests'],
allowJs: false,
includes: ['src'],
exclude: ['tests', 'examples', '*.js', 'scripts'],
esModuleInterop: true,
},
}),
Expand Down
2 changes: 1 addition & 1 deletion src/meilisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MeiliSearch extends MeiliAxiosWrapper
async isHealthy(): Promise<boolean> {
const url = '/health'

return await this.get(url).then((_) => true)
return await this.get(url).then(() => true)
}

/**
Expand Down
16 changes: 10 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ export interface AddDocumentParams {
primaryKey?: string
}

export type FacetFilter = (string | string[])[]
export type FacetFilter = Array<string | string[]>

export interface SearchParams<T> {
offset?: number
limit?: number
attributesToRetrieve?: Extract<keyof T, string>[] | Extract<keyof T, string>
attributesToRetrieve?:
| Array<Extract<keyof T, string>>
| Extract<keyof T, string>
attributesToCrop?:
| (Extract<keyof T, string> | '*')[]
| Array<Extract<keyof T, string> | '*'>
| (Extract<keyof T, string> | '*')
cropLength?: number
attributesToHighlight?:
| (Extract<keyof T, string> | '*')[]
| Array<Extract<keyof T, string> | '*'>
| (Extract<keyof T, string> | '*')
filters?: string
facetFilters?: string | FacetFilter | FacetFilter[]
Expand Down Expand Up @@ -114,7 +116,9 @@ export interface FieldFrequency {
export interface GetDocumentsParams<T> {
offset?: number
limit?: number
attributesToRetrieve?: Extract<keyof T, string>[] | Extract<keyof T, string>
attributesToRetrieve?:
| Array<Extract<keyof T, string>>
| Extract<keyof T, string>
}

export type GetDocumentsResponse<
Expand All @@ -131,7 +135,7 @@ export type GetDocumentsResponse<
: Array<Document<T>>

export type DocumentLike = { [Key in string]?: DocumentField }
export interface DocumentArray extends Array<DocumentField> {}
export type DocumentArray = DocumentField[]
export type DocumentField =
| string
| number
Expand Down
4 changes: 2 additions & 2 deletions tests/accept_new_fields_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe.each([
await client
.getIndex(index.uid)
.getAcceptNewFields()
.then((response: Boolean) => {
.then((response: boolean) => {
expect(response).toEqual(true)
})
})
Expand All @@ -47,7 +47,7 @@ describe.each([
await client
.getIndex(index.uid)
.getAcceptNewFields()
.then((response: Boolean) => {
.then((response: boolean) => {
expect(response).toEqual(false)
})
})
Expand Down
12 changes: 6 additions & 6 deletions tests/attributes_for_faceting_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ describe.each([
await client
.getIndex(index.uid)
.getAttributesForFaceting()
.then((response: String[]) => {
.then((response: string[]) => {
expect(response.sort()).toEqual([])
})
})
test(`${permission} key: Update attributes for filtering`, async () => {
const new_attributes_for_faceting = ['genre']
const newAttributesForFaceting = ['genre']
const { updateId } = await client
.getIndex(index.uid)
.updateAttributesForFaceting(new_attributes_for_faceting)
.updateAttributesForFaceting(newAttributesForFaceting)
.then((response: Types.EnqueuedUpdate) => {
expect(response).toHaveProperty('updateId', expect.any(Number))
return response
Expand All @@ -66,8 +66,8 @@ describe.each([
await client
.getIndex(index.uid)
.getAttributesForFaceting()
.then((response: String[]) => {
expect(response).toEqual(new_attributes_for_faceting)
.then((response: string[]) => {
expect(response).toEqual(newAttributesForFaceting)
})
})
test(`${permission} key: Reset attributes for filtering`, async () => {
Expand All @@ -82,7 +82,7 @@ describe.each([
await client
.getIndex(index.uid)
.getAttributesForFaceting()
.then((response: String[]) => {
.then((response: string[]) => {
expect(response.sort()).toEqual([])
})
})
Expand Down
7 changes: 0 additions & 7 deletions tests/client_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@ describe.each([
).rejects.toThrowError(`index already exists`)
})

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

test(`${permission} key: delete index with uid that does not exist should fail`, async () => {
const index = client.getIndex(uidNoPrimaryKey.uid)
await expect(index.deleteIndex()).rejects.toThrowError(
Expand Down
12 changes: 6 additions & 6 deletions tests/displayed_attributes_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ describe.each([
await client
.getIndex(index.uid)
.getDisplayedAttributes()
.then((response: String[]) => {
.then((response: string[]) => {
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
})
})
test(`${permission} key: Update displayed attributes`, async () => {
const new_da = ['title']
const newDisplayedAttribute = ['title']
const { updateId } = await client
.getIndex(index.uid)
.updateDisplayedAttributes(new_da)
.updateDisplayedAttributes(newDisplayedAttribute)
.then((response: Types.EnqueuedUpdate) => {
expect(response).toHaveProperty('updateId', expect.any(Number))
return response
Expand All @@ -66,8 +66,8 @@ describe.each([
await client
.getIndex(index.uid)
.getDisplayedAttributes()
.then((response: String[]) => {
expect(response).toEqual(new_da)
.then((response: string[]) => {
expect(response).toEqual(newDisplayedAttribute)
})
})
test(`${permission} key: Reset displayed attributes`, async () => {
Expand All @@ -82,7 +82,7 @@ describe.each([
await client
.getIndex(index.uid)
.getDisplayedAttributes()
.then((response: String[]) => {
.then((response: string[]) => {
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
})
})
Expand Down
6 changes: 3 additions & 3 deletions tests/distinct_attribute_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ describe.each([
})
})
test(`${permission} key: Update distinct attribute`, async () => {
const new_da = 'title'
const newDistinctAttribute = 'title'
const { updateId } = await client
.getIndex(index.uid)
.updateDistinctAttribute(new_da)
.updateDistinctAttribute(newDistinctAttribute)
.then((response: Types.EnqueuedUpdate) => {
expect(response).toHaveProperty('updateId', expect.any(Number))
return response
Expand All @@ -67,7 +67,7 @@ describe.each([
.getIndex(index.uid)
.getDistinctAttribute()
.then((response: string | null) => {
expect(response).toEqual(new_da)
expect(response).toEqual(newDistinctAttribute)
})
})
test(`${permission} key: Reset distinct attribute`, async () => {
Expand Down
1 change: 0 additions & 1 deletion tests/get_or_create_tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Types from '../src/types'
import {
clearAllIndexes,
config,
Expand Down
2 changes: 1 addition & 1 deletion tests/meilisearch-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const anonymousClient = new MeiliSearch({
host: HOST,
})

const clearAllIndexes = async (config: Types.Config) => {
const clearAllIndexes = async (config: Types.Config): Promise<void> => {
const client = new MeiliSearch(config)
const indexes = await client
.listIndexes()
Expand Down
6 changes: 3 additions & 3 deletions tests/ranking_rules_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe.each([
})
})
test(`${permission} key: Update ranking rules`, async () => {
const new_rr = ['asc(title)', 'typo', 'desc(description)']
const newRankingRules = ['asc(title)', 'typo', 'desc(description)']
const { updateId } = await client
.getIndex(index.uid)
.updateRankingRules(new_rr)
.updateRankingRules(newRankingRules)
.then((response: Types.EnqueuedUpdate) => {
expect(response).toHaveProperty('updateId', expect.any(Number))
return response
Expand All @@ -76,7 +76,7 @@ describe.each([
.getIndex(index.uid)
.getRankingRules()
.then((response: string[]) => {
expect(response).toEqual(new_rr)
expect(response).toEqual(newRankingRules)
})
})
test(`${permission} key: Reset ranking rules`, async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/search_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ describe.each([
await clearAllIndexes(config)
await masterClient.createIndex(index.uid)
await masterClient.createIndex(emptyIndex.uid)
const new_attributes_for_faceting = ['genre']
const newAttributesForFaceting = ['genre']
const { updateId: settingUpdateId } = await masterClient
.getIndex(index.uid)
.updateAttributesForFaceting(new_attributes_for_faceting)
.updateAttributesForFaceting(newAttributesForFaceting)
.then((response: Types.EnqueuedUpdate) => {
expect(response).toHaveProperty('updateId', expect.any(Number))
return response
Expand Down
12 changes: 6 additions & 6 deletions tests/searchable_attributes_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ describe.each([
await client
.getIndex(index.uid)
.getSearchableAttributes()
.then((response: String[]) => {
.then((response: string[]) => {
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
})
})
test(`${permission} key: Update searchable attributes`, async () => {
const new_da = ['title']
const newSearchableAttributes = ['title']
const { updateId } = await client
.getIndex(index.uid)
.updateSearchableAttributes(new_da)
.updateSearchableAttributes(newSearchableAttributes)
.then((response: Types.EnqueuedUpdate) => {
expect(response).toHaveProperty('updateId', expect.any(Number))
return response
Expand All @@ -66,8 +66,8 @@ describe.each([
await client
.getIndex(index.uid)
.getSearchableAttributes()
.then((response: String[]) => {
expect(response).toEqual(new_da)
.then((response: string[]) => {
expect(response).toEqual(newSearchableAttributes)
})
})
test(`${permission} key: Reset searchable attributes`, async () => {
Expand All @@ -82,7 +82,7 @@ describe.each([
await client
.getIndex(index.uid)
.getSearchableAttributes()
.then((response: String[]) => {
.then((response: string[]) => {
expect(response.sort()).toEqual(Object.keys(dataset[0]).sort())
})
})
Expand Down
Loading

0 comments on commit bdc5fac

Please sign in to comment.