Skip to content

Commit

Permalink
chore(javascript): use oxlint (#3895)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Oct 8, 2024
1 parent cf65d54 commit ed6f4ba
Show file tree
Hide file tree
Showing 90 changed files with 287 additions and 517 deletions.
139 changes: 0 additions & 139 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,145 +79,6 @@ module.exports = {
'yml/no-empty-mapping-value': 0,
},
},
{
// es linter
files: ['*.ts', '*.js'],

extends: [
'algolia',
'algolia/typescript',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],

env: {
es6: true,
},

parser: '@typescript-eslint/parser',

parserOptions: {
tsconfigRootDir: __dirname,
project: './**/tsconfig.json',
},

settings: {
'import/extensions': ['.js', '.ts'],
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/ignore': ['node_modules'],
},

plugins: ['algolia', 'unused-imports'],

rules: {
// disabled
'no-bitwise': 0,
'max-classes-per-file': 0,
'no-continue': 0,
'@typescript-eslint/prefer-enum-initializers': 0,
'@typescript-eslint/no-namespace': 0,
'import/dynamic-import-chunkname': 0,

'unused-imports/no-unused-imports': 2,
'@typescript-eslint/no-unused-vars': 2,
'@typescript-eslint/consistent-indexed-object-style': 2,
'@typescript-eslint/member-ordering': [
'error',
{
default: [
'protected-instance-method',
'private-instance-method',
'public-instance-method',
],
},
],
'@typescript-eslint/no-restricted-types': [
'error',
{
types: {
String: {
message: 'Use `string` instead.',
fixWith: 'string',
},
Number: {
message: 'Use `number` instead.',
fixWith: 'number',
},
Boolean: {
message: 'Use `boolean` instead.',
fixWith: 'boolean',
},
Symbol: {
message: 'Use `symbol` instead.',
fixWith: 'symbol',
},
Object: {
message:
'The `Object` type is mostly the same as `unknown`. You probably want `Record<string, unknown>` instead. See https://github.com/typescript-eslint/typescript-eslint/pull/848',
fixWith: 'Record<string, unknown>',
},
'{}': {
message:
'The `{}` type is mostly the same as `unknown`. You probably want `Record<string, unknown>` instead.',
fixWith: 'Record<string, unknown>',
},
object: {
message:
'The `object` type is hard to use. Use `Record<string, unknown>` instead. See: https://github.com/typescript-eslint/typescript-eslint/pull/848',
fixWith: 'Record<string, unknown>',
},
Function: 'Use a specific function type instead, like `() => void`.',
},
},
],
'jsdoc/match-description': [
'error',
{
matchDescription: '^\n?([A-Z`\[\\d_][\\s\\S]*[.?!`]\\s*)?$'
},
],
},
},
{
files: ['clients/algoliasearch-client-javascript/packages/**/*.ts'],

rules: {
// For a wider browser support (IE>=11), we forbid those two
'no-restricted-syntax': [
'error',
{
selector: "LogicalExpression[operator='??']",
message:
'For wider browser support, nullish coalescing operator is not allowed.',
},
{
selector: 'ChainExpression',
message:
'For wider browser support, optional chaining is not allowed.',
},
],
'@typescript-eslint/prefer-optional-chain': 0,
}
},
{
files: ['clients/algoliasearch-client-javascript/packages/**/__tests__/**/*.ts'],

plugins: ['@vitest/eslint-plugin'],
},
{
files: ['guides/**/*.ts'],

rules: {
'no-console': 0,

// TODO: remove this after https://algolia.atlassian.net/browse/DI-2984
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/explicit-function-return-type': 0,
},
},
{
files: ['*.json'],
parserOptions: {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
run: yarn scripts:test

- name: Lint custom eslint plugin
run: yarn workspace eslint-plugin-automation-custom lint
run: yarn cli format javascript eslint

- name: Test custom eslint plugin
run: yarn workspace eslint-plugin-automation-custom test
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
.env
.pnp.cjs
.parcel-cache
**/.parcel-cache
**/.nx

yarn-error.log
debug.log
Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"generators/**/*.java": "yarn cli format java generators",
".github/**/*.yml": "yarn github-actions:lint --fix",
"*.json": "yarn fix:json",
"scripts/**/*.(js|ts|mjs|cjs)": "yarn scripts:lint --fix",
"scripts/**/*.(js|ts|mjs|cjs)": "yarn cli format javascript scripts",
"specs/**/*.yml": "yarn eslint --ext=yml --fix"
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ build
.gradle
target
bin
.nx
.parcel-cache
.yarn
builddir
14 changes: 13 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
"trailingComma": "all",
"singleQuote": true,
"plugins": [
"prettier-plugin-java"
"prettier-plugin-java",
"prettier-plugin-organize-imports"
],
"overrides": [
{
"files": "*.java",
"options": {
"printWidth": 140
}
},
{
"files": ["*.ts", "*.js", "*.mjs", "*.cjs"],
"options": {
"arrowParens": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"printWidth": 120,
"useTabs": false,
"quoteProps": "as-needed"
}
}
]
}
4 changes: 2 additions & 2 deletions clients/algoliasearch-client-javascript/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

- [d4df544d6](https://github.com/algolia/api-clients-automation/commit/d4df544d6) fix(specs): remove usage [skip-bc] ([#3691](https://github.com/algolia/api-clients-automation/pull/3691)) by [@kai687](https://github.com/kai687/)
- [d39b87726](https://github.com/algolia/api-clients-automation/commit/d39b87726) chore: assert node helpers ([#3689](https://github.com/algolia/api-clients-automation/pull/3689)) by [@shortcuts](https://github.com/shortcuts/)
- [46d9d8fd0](https://github.com/algolia/api-clients-automation/commit/46d9d8fd0) feat(specs): add (optional) _automaticInsights to search result ([#3688](https://github.com/algolia/api-clients-automation/pull/3688)) by [@raed667](https://github.com/raed667/)
- [46d9d8fd0](https://github.com/algolia/api-clients-automation/commit/46d9d8fd0) feat(specs): add (optional) \_automaticInsights to search result ([#3688](https://github.com/algolia/api-clients-automation/pull/3688)) by [@raed667](https://github.com/raed667/)

## [5.4.0](https://github.com/algolia/algoliasearch-client-javascript/compare/5.3.2...5.4.0)

Expand Down Expand Up @@ -765,7 +765,7 @@ New major version released! Browse [our documentation](https://www.algolia.com/d

## [5.0.0-alpha.12](https://github.com/algolia/algoliasearch-client-javascript/compare/5.0.0-alpha.11...5.0.0-alpha.12)

- [ff02ba09](https://github.com/algolia/api-clients-automation/commit/ff02ba09) fix(javascript): revert: do not send user-agent for Predict (#957) ([#919](https://github.com/algolia/api-clients-automation/pull/919)) by [@shortcuts](https://github.com/shortcuts/)
- [ff02ba09](https://github.com/algolia/api-clients-automation/commit/ff02ba09) fix(javascript): revert: do not send user-agent for Predict (#957) ([#919](https://github.com/algolia/api-clients-automation/pull/919)) by [@shortcuts](https://github.com/shortcuts/)

## [5.0.0-alpha.11](https://github.com/algolia/algoliasearch-client-javascript/compare/5.0.0-alpha.10...5.0.0-alpha.11)

Expand Down
4 changes: 1 addition & 3 deletions clients/algoliasearch-client-javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@

## 💡 Getting Started


To get started, you first need to install algoliasearch (or any other available API client package).
All of our clients comes with type definition, and are available for both browser and node environments.

### With a package manager


```bash
yarn add algoliasearch@5.8.0
# or
Expand Down Expand Up @@ -82,4 +80,4 @@ Encountering an issue? Before reaching out to support, we recommend heading to o

## 📄 License

The Algolia JavaScript API Client is an open-sourced software licensed under the [MIT license](LICENSE).
The Algolia JavaScript API Client is an open-sourced software licensed under the [MIT license](LICENSE).
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';

import type { Options } from 'tsup';

type PKG = {
Expand Down
4 changes: 1 addition & 3 deletions clients/algoliasearch-client-javascript/lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"version": "independent",
"useNx": true
}
6 changes: 1 addition & 5 deletions clients/algoliasearch-client-javascript/nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": [
"build:many",
"build:all",
"build"
]
"cacheableOperations": ["build:many", "build:all", "build"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint no-console: 0 */

import { vi, test, expect } from 'vitest';
import { expect, test, vi } from 'vitest';

import { LogLevelEnum } from '../../client-common/src/types';
import { createConsoleLogger } from '../../logger-console/src/logger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe, expect, test } from 'vitest';

import {
DEFAULT_CONNECT_TIMEOUT_BROWSER,
DEFAULT_READ_TIMEOUT_BROWSER,
DEFAULT_WRITE_TIMEOUT_BROWSER,
} from '@algolia/client-common';
import type { EchoResponse } from '@algolia/requester-testing';
import { describe, test, expect } from 'vitest';

import { browserEchoRequester } from '../../requester-testing/src/browserEchoRequester';
import { algoliasearch, apiClientVersion } from '../builds/browser';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint no-console: 0 */

import { vi, test, expect } from 'vitest';
import { expect, test, vi } from 'vitest';

import { LogLevelEnum } from '../../client-common/src/types';
import { createConsoleLogger } from '../../logger-console/src/logger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint no-console: 0 */

import { vi, test, expect } from 'vitest';
import { expect, test, vi } from 'vitest';

import { LogLevelEnum } from '../../client-common/src/types';
import { createConsoleLogger } from '../../logger-console/src/logger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi, describe, test, beforeEach, expect } from 'vitest';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { createBrowserLocalStorageCache } from '../../cache';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest';
import { describe, expect, test } from 'vitest';

import {
createBrowserLocalStorageCache,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi, describe, test, beforeEach, expect } from 'vitest';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { createMemoryCache } from '../../cache';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi, describe, test, beforeEach, expect } from 'vitest';
import { beforeEach, describe, expect, test, vi } from 'vitest';

import { createNullCache } from '../../cache';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest';
import { describe, expect, test } from 'vitest';

import { createIterablePromise } from '../createIterablePromise';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint no-console: 0 */

import { vi, describe, test, expect } from 'vitest';
import { describe, expect, test, vi } from 'vitest';

import { createNullLogger } from '../../logger';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { FallbackableCacheOptions, Cache, CacheEvents } from '../types';

import type { Cache, CacheEvents, FallbackableCacheOptions } from '../types';
import { createNullCache } from './createNullCache';

export function createFallbackableCache(options: FallbackableCacheOptions): Cache {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AlgoliaAgentOptions, AlgoliaAgent } from './types';
import type { AlgoliaAgent, AlgoliaAgentOptions } from './types';

export function createAlgoliaAgent(version: string): AlgoliaAgent {
const algoliaAgent = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAlgoliaAgent } from './createAlgoliaAgent';
import type { AlgoliaAgentOptions, AlgoliaAgent } from './types';
import type { AlgoliaAgent, AlgoliaAgentOptions } from './types';

export type GetAlgoliaAgent = {
algoliaAgents: AlgoliaAgentOptions[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import type {
EndRequest,
Host,
QueryParameters,
Request,
RequestOptions,
Response,
StackFrame,
TransporterOptions,
Transporter,
QueryParameters,
TransporterOptions,
} from '../types';

import { createStatefulHost } from './createStatefulHost';
import { RetryError } from './errors';
import { deserializeFailure, deserializeSuccess, serializeData, serializeHeaders, serializeUrl } from './helpers';
import { isRetryable, isSuccess } from './responses';
import { stackTraceWithoutCredentials, stackFrameWithoutCredentials } from './stackTrace';
import { stackFrameWithoutCredentials, stackTraceWithoutCredentials } from './stackTrace';

type RetryableOptions = {
hosts: Host[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Headers, Host, QueryParameters, Request, RequestOptions, Response, StackFrame } from '../types';

import { ApiError, DeserializationError, DetailedApiError } from './errors';

export function shuffle<TData>(array: TData[]): TData[] {
Expand Down
Loading

0 comments on commit ed6f4ba

Please sign in to comment.