diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0c8d273 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "eslint.workingDirectories": [ + {"directory": "./packages/core", "changeProcessCWD": true}, + {"directory": "./packages/react", "changeProcessCWD": true} + ] +} diff --git a/config/eslint-config/index.js b/config/eslint-config/index.js index 631dfb3..457ab1c 100644 --- a/config/eslint-config/index.js +++ b/config/eslint-config/index.js @@ -4,12 +4,14 @@ module.exports = { ecmaVersion: 2019, sourceType: 'module', }, - plugins: ['@typescript-eslint'], + plugins: ['@typescript-eslint', 'require-extensions'], + extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended-type-checked', 'plugin:react/recommended', 'plugin:react-hooks/recommended', + 'plugin:require-extensions/recommended', 'prettier', ], rules: { diff --git a/config/eslint-config/package.json b/config/eslint-config/package.json index f60d7bd..f751cfe 100644 --- a/config/eslint-config/package.json +++ b/config/eslint-config/package.json @@ -5,5 +5,8 @@ "main": "index.js", "files": [ "index.js" - ] + ], + "devDependencies": { + "eslint-plugin-require-extensions": "^0.1.3" + } } diff --git a/packages/core/.eslintrc.cjs b/packages/core/.eslintrc.cjs index 37b6c39..267f462 100644 --- a/packages/core/.eslintrc.cjs +++ b/packages/core/.eslintrc.cjs @@ -2,7 +2,7 @@ module.exports = { root: true, extends: ['@formulier/eslint-config'], parserOptions: { - project: true, + project: './tsconfig.lint.json', tsConfigRootDir: __dirname, }, } diff --git a/packages/core/tests/array-utils.test.ts b/packages/core/tests/array-utils.test.ts index acd0252..14e17f8 100644 --- a/packages/core/tests/array-utils.test.ts +++ b/packages/core/tests/array-utils.test.ts @@ -1,6 +1,6 @@ import {expect, it} from 'vitest' -import {insert, move, push, remove, swap} from '../src/array-utils' +import {insert, move, push, remove, swap} from '../src/array-utils.js' const [A, B, C, D] = ['a', 'b', 'c', 'd'] diff --git a/packages/core/tests/form.test.ts b/packages/core/tests/form.test.ts index 3b8987d..05f8121 100644 --- a/packages/core/tests/form.test.ts +++ b/packages/core/tests/form.test.ts @@ -1,7 +1,7 @@ import {expect, it, vi} from 'vitest' -import {Formulier} from '../src/form' -import {getPath} from '../src/state-utils' +import {Formulier} from '../src/form.js' +import {getPath} from '../src/state-utils.js' const INITIAL_VALUES = {a: {b: {c: 'c', d: 'd'}}} diff --git a/packages/core/tests/state-utils.test.ts b/packages/core/tests/state-utils.test.ts index 0e5b639..fbea130 100644 --- a/packages/core/tests/state-utils.test.ts +++ b/packages/core/tests/state-utils.test.ts @@ -1,6 +1,6 @@ import {describe, expect, it} from 'vitest' -import {getPath, isInteger, isObject, removeKey, setKey, setPath, toPath} from '../src/state-utils' +import {getPath, isInteger, isObject, removeKey, setKey, setPath, toPath} from '../src/state-utils.js' const SOURCE = { a: {b: {c: 'c'}}, diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index cbde135..08dfec6 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "@formulier/tsconfig/base", - "include": ["src/index.ts"], + "files": ["src/index.ts"], "compilerOptions": { "outDir": "dist", "types": ["vitest/importMeta"] diff --git a/packages/core/tsconfig.lint.json b/packages/core/tsconfig.lint.json new file mode 100644 index 0000000..cfa64ac --- /dev/null +++ b/packages/core/tsconfig.lint.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*", "tests/**/*"] +} diff --git a/packages/react/.eslintrc.cjs b/packages/react/.eslintrc.cjs index 37b6c39..267f462 100644 --- a/packages/react/.eslintrc.cjs +++ b/packages/react/.eslintrc.cjs @@ -2,7 +2,7 @@ module.exports = { root: true, extends: ['@formulier/eslint-config'], parserOptions: { - project: true, + project: './tsconfig.lint.json', tsConfigRootDir: __dirname, }, } diff --git a/packages/react/cypress/component/form-tests.cy.tsx b/packages/react/cypress/component/form-tests.cy.tsx index fd3dcd7..50ded28 100644 --- a/packages/react/cypress/component/form-tests.cy.tsx +++ b/packages/react/cypress/component/form-tests.cy.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import {FormProvider, useCreateForm, useFormField, useFormInstance} from '../../src' +import {FormProvider, useCreateForm, useFormField, useFormInstance} from '../../src/index.js' function Form({children}: {children: React.ReactNode}) { const form = useCreateForm({ diff --git a/packages/react/cypress/support/component.tsx b/packages/react/cypress/support/component.tsx index 8e8f5ac..4e0fa36 100644 --- a/packages/react/cypress/support/component.tsx +++ b/packages/react/cypress/support/component.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import {mount} from 'cypress/react18' -import './commands' +import './commands.js' declare global { // eslint-disable-next-line @typescript-eslint/no-namespace diff --git a/packages/react/tests/use-create-form.test.ts b/packages/react/tests/use-create-form.test.ts index c3ed365..e13e30c 100644 --- a/packages/react/tests/use-create-form.test.ts +++ b/packages/react/tests/use-create-form.test.ts @@ -1,8 +1,8 @@ import {expect, it} from 'vitest' import {renderHook} from '@testing-library/react' -import {useCreateForm} from '../src/form' -import {useFormField} from '../src/field' +import {useCreateForm} from '../src/form.js' +import {useFormField} from '../src/field.js' interface FormState { a: {b: {c: string; d: string}} diff --git a/packages/react/tests/use-form-field.test.ts b/packages/react/tests/use-form-field.test.ts index 7911387..1406f9b 100644 --- a/packages/react/tests/use-form-field.test.ts +++ b/packages/react/tests/use-form-field.test.ts @@ -1,10 +1,10 @@ import {expect, it} from 'vitest' import {renderHook} from '@testing-library/react' -import {useCreateForm} from '../src/form' -import {useFormField} from '../src/field' +import {useCreateForm} from '../src/form.js' +import {useFormField} from '../src/field.js' -import type {FieldOptions} from '../src/types' +import type {FieldOptions} from '../src/types.js' interface FormState { a: {b: {c: string; d: string}} diff --git a/packages/react/tsconfig.json b/packages/react/tsconfig.json index 9571fbe..a673caf 100644 --- a/packages/react/tsconfig.json +++ b/packages/react/tsconfig.json @@ -3,7 +3,7 @@ "files": ["src/index.ts"], "compilerOptions": { "outDir": "dist", - "jsx": "react-jsx", - "types": ["vitest/importMeta"] + "types": ["vitest/importMeta"], + "jsx": "react-jsx" } } diff --git a/packages/react/tsconfig.lint.json b/packages/react/tsconfig.lint.json new file mode 100644 index 0000000..9fb6d41 --- /dev/null +++ b/packages/react/tsconfig.lint.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*", "tests/**/*", "cypress/**/*"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe84026..6d35e5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,7 +45,11 @@ importers: specifier: ^5.3.3 version: 5.3.3 - config/eslint-config: {} + config/eslint-config: + devDependencies: + eslint-plugin-require-extensions: + specifier: ^0.1.3 + version: 0.1.3(eslint@8.56.0) config/tsconfig: {} @@ -3013,6 +3017,15 @@ packages: string.prototype.matchall: 4.0.10 dev: true + /eslint-plugin-require-extensions@0.1.3(eslint@8.56.0): + resolution: {integrity: sha512-T3c1PZ9PIdI3hjV8LdunfYI8gj017UQjzAnCrxuo3wAjneDbTPHdE3oNWInOjMA+z/aBkUtlW5vC0YepYMZIug==} + engines: {node: '>=16'} + peerDependencies: + eslint: '*' + dependencies: + eslint: 8.56.0 + dev: true + /eslint-scope@7.2.2: resolution: {integrity: sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}