Skip to content

Commit

Permalink
chore: configure ESLint to new configuration including tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bengeois authored and VaiTon committed Oct 31, 2024
1 parent 53ebeef commit eefaaad
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 35 deletions.
26 changes: 0 additions & 26 deletions .eslintrc.js

This file was deleted.

42 changes: 42 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import globals from "globals";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import tsParser from "@typescript-eslint/parser";

export default tseslint.config(
{
files: ["**/*.ts"],
languageOptions: {
parser: tsParser,
parserOptions: {
project: "./tsconfig.json",
},
},
plugins: {
"@typescript-eslint": tseslint,
},
rules: {
...eslint.configs.recommended.rules, // Include recommended JS rules
...tseslint.configs.recommended.rules, // Include recommended TS rules
},
},
{
languageOptions: {
globals: { ...globals.browser, ...globals.node, ...globals.jest },
},
},
{
// Global ignore patterns
ignores: [
"dist",
"docs",
".yarn",
"node_modules",
"**/node_modules",
"src/schemas",
"coverage",
"*.config.mjs",
"jest.config.ts",
],
}
);
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"types": "dist/main.d.ts",
"scripts": {
"prepack": "yarn run build",
"build": "tsc",
"build": "tsc -p tsconfig.build.json",
"build:docs": "typedoc src/main.ts",
"commitmsg": "commitlint -quiet=0 --extends=@commitlint/config-conventional -e",
"precommit": "standard `git diff --name-only --staged --relative | grep '.js$'`",
Expand All @@ -20,7 +20,8 @@
"api:folksonomy": "openapi-typescript https://api.folksonomy.openfoodfacts.org/openapi.json --output src/schemas/folksonomy.ts",
"api:nutripatrol": "openapi-typescript https://nutripatrol.openfoodfacts.org/api/openapi.json --output src/schemas/nutripatrol.ts",
"check": "yarn run lint && yarn run test",
"lint": "prettier --check . && eslint .",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"format": "prettier --write .",
"fix": "standard --fix",
"test": "jest",
Expand Down Expand Up @@ -56,20 +57,24 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.8.5",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^9.1.1",
"formdata-node": "^6.0.3",
"globals": "^15.11.0",
"jest": "^29.7.0",
"openapi-typescript": "^6.7.4",
"prettier": "^3.1.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typedoc": "^0.26.10",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"typescript-eslint": "^8.12.2"
},
"packageManager": "[email protected]"
}
}
5 changes: 3 additions & 2 deletions src/nutripatrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class NutriPatrol {
try {
const fct = methods[method] as any;
const res = await fct(path as any, options as any);
let errorDetails: NutriPatrolError | undefined;

if (!res.response.ok) {
switch (res.response.status) {
Expand All @@ -70,7 +71,7 @@ export class NutriPatrol {
},
} as NutriPatrolError;
default:
const errorDetails = await res.response.json();
errorDetails = await res.response.json();
return {
error: {
statusCode: res.response.status,
Expand All @@ -93,7 +94,7 @@ export class NutriPatrol {
}

return data;
} catch (error) {
} catch {
return {
error: {
statusCode: 500,
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
},
"include": ["src"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
},
"forceConsistentCasingInFileNames": true,
"target": "ES2015",
"rootDir": "./src",
"rootDir": ".",
"module": "CommonJS",
"lib": ["ES2022", "DOM"],
"declaration": true,
"outDir": "./dist",
"strict": true,
"esModuleInterop": true
},
"exclude": ["node_modules", "dist", "tests", "jest.config.ts"]
"exclude": ["node_modules", "dist", "jest.config.ts", "coverage", "docs"]
}
Loading

0 comments on commit eefaaad

Please sign in to comment.