@kirill.konshin/lint 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -0
- package/index.js +657 -0
- package/lintPrepare.js +326 -0
- package/package.json +94 -0
- package/ruleTestColocation.js +50 -0
- package/rules/code-style.md +6 -0
- package/rules/electron.md +25 -0
- package/rules/expo.md +4 -0
- package/rules/github.md +71 -0
- package/rules/gitlab.md +37 -0
- package/rules/i18n.md +6 -0
- package/rules/jest.md +9 -0
- package/rules/monorepo-turbo-nx.md +56 -0
- package/rules/mui.md +10 -0
- package/rules/nextjs.md +69 -0
- package/rules/npm-yarn.md +61 -0
- package/rules/nx.md +31 -0
- package/rules/react.md +87 -0
- package/rules/redux.md +4 -0
- package/rules/storybook.md +38 -0
- package/rules/tailwind.md +17 -0
- package/rules/testing.md +25 -0
- package/rules/turbo.md +58 -0
- package/rules/typescript.md +95 -0
- package/rules/vite.md +21 -0
- package/rules/webstorm.md +133 -0
- package/skills/lint-repo.md +58 -0
package/rules/mui.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects with MUI
|
|
4
|
+
paths:
|
|
5
|
+
- '**/*.tsx'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
- To use MUI default classes always use following notation because it's the only one that works with minification:
|
|
9
|
+
- Import: `import Input, { inputClasses } from '@mui/material/Input';`
|
|
10
|
+
- Usage: `<Box sx={{ [``& .${inputClasses.root}``]: { /* styles */ } }}><Input /></Box>`
|
package/rules/nextjs.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects which use Next.js
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
_EVERY_ Next.js page, layout, route handler or component must adhere to policy unless explicitly prohibited in comment before the component definition.
|
|
7
|
+
|
|
8
|
+
# General Guidelines
|
|
9
|
+
|
|
10
|
+
- Prefer Route Handlers for redirects
|
|
11
|
+
- Never use Pages Router
|
|
12
|
+
- Always use App Router
|
|
13
|
+
- Use `iron-session` for authentication
|
|
14
|
+
- `package.json` MUST ALWAYS have version of Next.js, NEVER `*`, otherwise Vercel will fall into legacy mode instead of serverless
|
|
15
|
+
|
|
16
|
+
# Layouts
|
|
17
|
+
|
|
18
|
+
Always use https://nextjs.org/docs/app/api-reference/file-conventions/layout#layout-props-helper:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import React from 'react';
|
|
22
|
+
|
|
23
|
+
export default function Layout({ children, analytics }: LayoutProps<'/dashboard'>) {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
{children}
|
|
27
|
+
{/* If you have app/dashboard/@analytics, it appears as a typed slot: */}
|
|
28
|
+
{analytics}
|
|
29
|
+
</>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Check auth in layouts pattern
|
|
35
|
+
|
|
36
|
+
Prefer `/app/(auth)/layout.tsx` as root layout for auth protection. This won't create path segment, but will protect all routes under it.
|
|
37
|
+
|
|
38
|
+
Route Handlers are not protected by layouts, so add auth check there too.
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import React from 'react';
|
|
42
|
+
import { redirect } from 'next/navigation';
|
|
43
|
+
import { getToken } from '@/lib/auth';
|
|
44
|
+
|
|
45
|
+
export default async function Layout({ children }: LayoutProps<'/dashboard'>) {
|
|
46
|
+
if (!(await getToken())) {
|
|
47
|
+
redirect('/login');
|
|
48
|
+
}
|
|
49
|
+
return <>{children}</>;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# Pages
|
|
54
|
+
|
|
55
|
+
- https://nextjs.org/docs/app/api-reference/file-conventions/dynamic-routes
|
|
56
|
+
- https://nextjs.org/docs/app/getting-started/layouts-and-pages#rendering-with-search-params
|
|
57
|
+
- https://nextjs.org/docs/app/getting-started/layouts-and-pages#creating-a-dynamic-segment
|
|
58
|
+
|
|
59
|
+
Always use https://nextjs.org/docs/app/api-reference/file-conventions/page#page-props-helper.
|
|
60
|
+
|
|
61
|
+
Always use the following pattern for all pages:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
export default async function Page({ params, searchParams }: PageProps<'/blog/[slug]'>) {
|
|
65
|
+
const { slug } = await params;
|
|
66
|
+
const { filter } = await searchParams;
|
|
67
|
+
return <h1>Blog post: {slug}</h1>;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: NPM & Yarn patterns
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
- Prefer using Corepack for all new projects.
|
|
7
|
+
- Prefer Yarn v4+ for all new projects.
|
|
8
|
+
|
|
9
|
+
# Lifecycle Scripts: `prepare` vs `postinstall`
|
|
10
|
+
|
|
11
|
+
- ⚠️ ALWAYS put install-time setup (husky, codegen, cache warmup) in the install lifecycle — `prepare` by default, `postinstall` for a private root (tradeoff below)
|
|
12
|
+
- ⚠️ Yarn 2+ (Berry) skips top-level `prepare` on install ([lifecycle scripts](https://yarnpkg.com/advanced/lifecycle-scripts)) — run `yarn prepare` yourself / in CI. For a **private** root, prefer `postinstall`: Yarn does run it on install, so hooks land automatically (incl. CI) with no manual step and no [pinst](https://github.com/typicode/pinst) guard. Keep `prepare` for **published** packages — an unguarded `postinstall` would run on consumers' installs.
|
|
13
|
+
|
|
14
|
+
# Prefer Libraries with Long History
|
|
15
|
+
|
|
16
|
+
- Prefer libraries that have a long history of updates and are well-maintained, and are not deprecated.
|
|
17
|
+
- Always try to use the latest version of a library.
|
|
18
|
+
- Always try to find if there is a suitable library for a given task before writing custom code, ask user if library is not very popular.
|
|
19
|
+
|
|
20
|
+
# Consistent versions
|
|
21
|
+
|
|
22
|
+
In Monorepos pin versions of sub-packages to main.
|
|
23
|
+
|
|
24
|
+
https://github.com/raineorshine/npm-check-updates/issues/1332#issuecomment-1717862332
|
|
25
|
+
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
|
|
26
|
+
|
|
27
|
+
Root `package.json`:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"installConfig": {
|
|
32
|
+
"hoistingLimits": "dependencies"
|
|
33
|
+
},
|
|
34
|
+
"overrides": {
|
|
35
|
+
"next": "$next",
|
|
36
|
+
"eslint": "$eslint",
|
|
37
|
+
"typescript": "$typescript"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
All other `package.json`:
|
|
43
|
+
|
|
44
|
+
```jsonc
|
|
45
|
+
{
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"next": "16.0.0", // except next, see nextjs.md
|
|
48
|
+
"typescript": "*", // vividly express version does not matter
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# `.yarnrc.yml`
|
|
54
|
+
|
|
55
|
+
```yml
|
|
56
|
+
yarnPath: .yarn/releases/yarn-4.5.1.cjs
|
|
57
|
+
nodeLinker: node-modules
|
|
58
|
+
# compressionLevel: mixed
|
|
59
|
+
# enableGlobalCache: false
|
|
60
|
+
# checksumBehavior: update
|
|
61
|
+
```
|
package/rules/nx.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for MONOREPO projects which use Turbo or NX
|
|
4
|
+
paths:
|
|
5
|
+
- '**/nx.json'
|
|
6
|
+
- '**/package.json'
|
|
7
|
+
- '**/project.json'
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# NX
|
|
11
|
+
|
|
12
|
+
- If NX is used root `package.json` must have `nx show projects > /dev/null` in the `prepare`/`postinstall` script, so the project graph cache exists for tools that read it outside `nx` — e.g. `@nx/eslint-plugin` rules in a bare `eslint` run silently skip without it. With `prepare`, Yarn 2+ skips it on install — run `yarn prepare` explicitly (after cloning + as a CI step); with `postinstall` (private root) Yarn runs it on install, so no extra step
|
|
13
|
+
- NX Release (v23+) with conventional commits silently demotes bumps for `0.x` packages (breaking → minor, `feat` → patch) while the log still claims `Applied semver relative bump "minor"`;
|
|
14
|
+
- set `release.version.adjustSemverBumpsForZeroMajorVersion: false` in `nx.json` if `feat:` must bump minor before `1.0.0`
|
|
15
|
+
- Root NX task-script convention: bare name = `nx run-many -t <target>` over all projects (`build`/`test`/`start`/`serve`), with concurrency flags set once here;
|
|
16
|
+
- Add a NX scripts to root `package.json`:
|
|
17
|
+
- `<target>:packages` scopes to publishable libs (`yarn <target> --projects '@scope/*'`);
|
|
18
|
+
- `<target>:affected` = `nx affected -t <target>` for CI (exclude demos, diff vs `origin/main`)
|
|
19
|
+
- `release:preview` script (`nx release --dry-run --verbose`) to preview, per package, the resolved-from tag, the bump reason (or `🚫 No changes`), and covered commits before releasing;
|
|
20
|
+
- the `changelog`/`version` subcommands can't substitute (changelog needs an explicit version, version rejects a top-level `release.git`).
|
|
21
|
+
- Build-free check of one package's range: `git log <pkg-tag>..HEAD -- <pkg-dir>`
|
|
22
|
+
|
|
23
|
+
- Commit changes to root `package.json` or `yarn.lock` or `nx.json` ONLY as `chore` otherwise ALL packages will be bumped
|
|
24
|
+
- https://github.com/nrwl/nx/issues/34542 (root file changes → all bumped)
|
|
25
|
+
- NX Release attributes commits to projects by FILE PATHS via `nx affected` against the CURRENT graph — commit scope (`feat(pkg):`) does not limit attribution
|
|
26
|
+
- NEVER fully delete (or `nx g move`-rename) a package: a historical `feat`/`fix` that touched a `package.json`/`project.json` which no longer exists on disk is attributed to ALL projects, and mass-bumps the whole workspace on the very next release run (even a `chore` push);
|
|
27
|
+
- ALWAYS leave a tombstone `package.json` at the EXACT old path (`private: true`, no scripts), and exclude it in `release.projects` (`!packages/<retired>`) so it's never versioned/published;
|
|
28
|
+
- removable only once EVERY package has a tag newer than the last `feat`/`fix` that touched the retired `package.json`;
|
|
29
|
+
- moving the tombstone elsewhere breaks it — the check is on the historical file path
|
|
30
|
+
- https://github.com/nrwl/nx/issues/33374 (delete/rename → all released)
|
|
31
|
+
- https://github.com/nrwl/nx/issues/34277 (scans too much, slow, warnings for removed)
|
package/rules/react.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects which use React
|
|
4
|
+
paths:
|
|
5
|
+
- '**/*.tsx'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
**ALL** React component must adhere to policy unless explicitly prohibited in comment before the component definition.
|
|
9
|
+
|
|
10
|
+
- Prefer `PropsWithChildren<{...}>` to declare props of components with optional children
|
|
11
|
+
- `children: ReactNode` if required
|
|
12
|
+
- `JSX.Element` if exactly one JSX element like `<div />`
|
|
13
|
+
- `ReactElement<...>` if object-specific
|
|
14
|
+
- If extending functionality of existing component use it's Props:
|
|
15
|
+
- `type DerivedProps = CmpProps & {...}` if `Cmp` provides `CmpProps` (preferred)
|
|
16
|
+
- `type DerivedProps = ComponentProps<typeof Cmp> & {...}` if `Cmp` does provide `CmpProps`
|
|
17
|
+
- ALWAYS prefer using memoized components
|
|
18
|
+
- Memoize everything
|
|
19
|
+
- Prefer `memo<Props>(...)`
|
|
20
|
+
- Use `FC<Props> = memo(...)` if `--isolatedDeclarations` flag is on
|
|
21
|
+
- ALWAYS use `useCallback` if React Compiler is not enabled in project
|
|
22
|
+
- Prefer to set defaults while destructuring props: `function Cmp({ children = 'xxx' })` where applicable
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { FC, memo } from 'react';
|
|
26
|
+
export type CmpProps = {
|
|
27
|
+
/* types */
|
|
28
|
+
}; // or never if no props needed
|
|
29
|
+
export const Cmp: FC<CmpProps> = memo(function Cmp(props) {
|
|
30
|
+
/* code */
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
# Object Merging
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
const containerDefaultProps = SOME_GLOBAL_SETTING ? { ... } : {};
|
|
38
|
+
|
|
39
|
+
<Container {...{ ...containerDefaultProps, ...containerProps }} prop={override} />;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
# Context
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
'use client';
|
|
46
|
+
|
|
47
|
+
import { createContext, useContext, useMemo, useState, ReactNode } from 'react';
|
|
48
|
+
|
|
49
|
+
// Always type Context explicitly
|
|
50
|
+
// Never export context itself
|
|
51
|
+
const ExampleContext = createContext<{
|
|
52
|
+
setEnabled: (prev: boolean) => boolean;
|
|
53
|
+
enabled: false;
|
|
54
|
+
}>(null);
|
|
55
|
+
|
|
56
|
+
// Export provider
|
|
57
|
+
export function ExampleContextProvider({ children }: { children: ReactNode }) {
|
|
58
|
+
// context state & functions
|
|
59
|
+
const [enabled, setEnabled] = useState(true);
|
|
60
|
+
|
|
61
|
+
// memoize context value
|
|
62
|
+
const value = useMemo(() => ({ enabled, setEnabled }), [enabled, setEnabled]);
|
|
63
|
+
|
|
64
|
+
return <ExampleContext.Provider value={control}>{children}</ExampleContext.Provider>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Export hook for consumers
|
|
68
|
+
export const useExampleContext = () => {
|
|
69
|
+
return useContext(ExampleContext);
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
# AbortController Pattern
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const ctrl = new AbortController();
|
|
78
|
+
const { signal } = ctrl;
|
|
79
|
+
|
|
80
|
+
window.addEventListener('keydown', handler, { signal, capture: true }); // capture for illustration purpose
|
|
81
|
+
window.addEventListener('keyup', handler, { signal });
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
ctrl.abort(); // instead of manual removeEventListener
|
|
85
|
+
};
|
|
86
|
+
}, [deps]);
|
|
87
|
+
```
|
package/rules/redux.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects which use Storybook
|
|
4
|
+
paths:
|
|
5
|
+
- '**/*.stories.tsx'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
- Story files: `*.stories.tsx`
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
12
|
+
import { ComponentName } from './componentName';
|
|
13
|
+
|
|
14
|
+
const meta: Meta<typeof ComponentName> = {
|
|
15
|
+
title: 'Category / ComponentName',
|
|
16
|
+
component: ComponentName,
|
|
17
|
+
parameters: {
|
|
18
|
+
layout: 'centered',
|
|
19
|
+
},
|
|
20
|
+
tags: ['autodocs'],
|
|
21
|
+
argTypes: {
|
|
22
|
+
// control definitions
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
|
|
28
|
+
type Story = StoryObj<typeof meta>;
|
|
29
|
+
|
|
30
|
+
export const Default: Story = {};
|
|
31
|
+
|
|
32
|
+
// Export presets with args
|
|
33
|
+
export const WithArgs: Story = {
|
|
34
|
+
args: {
|
|
35
|
+
// props
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects which use Tailwind
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
- Always use latest version of Tailwind
|
|
7
|
+
- Default UI library for use with Tailwind is Hero UI v3+
|
|
8
|
+
- Use the smallest possible configuration of Tailwind and Hero UI, adhere to their best practices (for Vite, Next.js integration, etc.)
|
|
9
|
+
|
|
10
|
+
# Hero UI
|
|
11
|
+
|
|
12
|
+
- Always extract Compound Components as reusable UI kit library of project-specific Components if used more than once, never duplicate boilerplate, except highly custom ones, if in doubt ask confirmation from user
|
|
13
|
+
- Use the shortest config: `@import "@heroui/react/styles";` in entrypoint CSS file is enough
|
|
14
|
+
|
|
15
|
+
# Webstorm
|
|
16
|
+
|
|
17
|
+
See [specific webstorm instructions](webstorm.md) if project uses Tailwind.
|
package/rules/testing.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects with tests
|
|
4
|
+
paths:
|
|
5
|
+
- '**/jest.config.{ts,js,mjs,cjs}'
|
|
6
|
+
- '**/vite.config.{ts,js,mjs,cjs}'
|
|
7
|
+
- '**/*.test.ts'
|
|
8
|
+
- '**/*.spec.ts'
|
|
9
|
+
- '**/*.fixture.ts'
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
- If project use `vite` use `vitest`, otherwise `jest`
|
|
13
|
+
- If project needs browser-based testing use `playwright`
|
|
14
|
+
- Naming
|
|
15
|
+
- `*.test.ts` for unit tests
|
|
16
|
+
- `*.spec.ts` for e2e or integration tests (require running DEV server)
|
|
17
|
+
- `*.fixture.ts` for test helpers, mocks, worker fixtures
|
|
18
|
+
- Organization
|
|
19
|
+
- Use `describe(...)` to group related tests, nesting allowed and preferred
|
|
20
|
+
- Set timeouts on describe blocks or individual tests for slow tests to make them visible
|
|
21
|
+
- Prefer to use `vi.fn()` or `jest.fn()` to create mock functions
|
|
22
|
+
- Mock entire test-specific class implementations via `class Testable extend ClassToBeTested {}`
|
|
23
|
+
- Mock class methods/values or wrap originals in mocks for visibility
|
|
24
|
+
- Create helper/factory functions for repeated setup, keep tests DRY
|
|
25
|
+
- Prefer tests to be logic-free
|
package/rules/turbo.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for MONOREPO projects which use Turbo or NX
|
|
4
|
+
paths:
|
|
5
|
+
- '**/turbo.json'
|
|
6
|
+
- '**/package.json'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Root
|
|
10
|
+
|
|
11
|
+
```jsonc
|
|
12
|
+
{
|
|
13
|
+
"$schema": "https://turbo.build/schema.json",
|
|
14
|
+
"globalDependencies": ["tsconfig.json"],
|
|
15
|
+
"tasks": {
|
|
16
|
+
|
|
17
|
+
// define task defaults
|
|
18
|
+
|
|
19
|
+
"build": {},
|
|
20
|
+
"wait": {
|
|
21
|
+
"cache": false
|
|
22
|
+
},
|
|
23
|
+
"test": {
|
|
24
|
+
"outputs": ["coverage/**/*"]
|
|
25
|
+
},
|
|
26
|
+
"start": {
|
|
27
|
+
"persistent": true,
|
|
28
|
+
"cache": false
|
|
29
|
+
"dependsOn": ["^wait"]
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// root tasks
|
|
33
|
+
|
|
34
|
+
"//#lint": {
|
|
35
|
+
"cache": false
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
# Leaf
|
|
42
|
+
|
|
43
|
+
```jsonc
|
|
44
|
+
{
|
|
45
|
+
"$schema": "https://turbo.build/schema.json",
|
|
46
|
+
"extends": ["//"],
|
|
47
|
+
"tasks": {
|
|
48
|
+
"build:demo": {
|
|
49
|
+
"dependsOn": ["^build"],
|
|
50
|
+
// list minimal amount of inputs & outputs
|
|
51
|
+
"inputs": ["$TURBO_DEFAULT$", "src/**/*", "assets/**/*"],
|
|
52
|
+
"outputs": ["dist/**/*"],
|
|
53
|
+
// list all ENV that affect build and must invalidate cache
|
|
54
|
+
"env": ["CSC_KEY_PASSWORD", "CSC_IDENTITY_AUTO_DISCOVERY"],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
```
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects with tests
|
|
4
|
+
paths:
|
|
5
|
+
- '**/*.js'
|
|
6
|
+
- '**/*.mjs'
|
|
7
|
+
- '**/*.cjs'
|
|
8
|
+
- '**/*.ts'
|
|
9
|
+
- '**/*.tsx'
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
- ALL projects must use TypeScript by default
|
|
13
|
+
- JavaScript is acceptable for service scripts, but discouraged, use `ts-node`
|
|
14
|
+
- ALL configs should use TypeScript if possible via `defineConfig` or at least import TS type for configuration.
|
|
15
|
+
- Prefer short-circuit evaluation and early exit
|
|
16
|
+
- Use structured logging with context, consider adding function arguments to log:
|
|
17
|
+
- `console.log('[MODULE] FuncionName did something', { isDev, appPath, useStaticInDev });`
|
|
18
|
+
- `console.log('[APP] Static Server', fileUrl, '->', filePath);`
|
|
19
|
+
- Prefer Optional Chaining `onClose?.();` or `options?.signal?.addEventListener('abort', ...)` instead `if`s or ternaries
|
|
20
|
+
- Prefer Nullish Coalescing `id ?? 'default'` instead of ternaries like `!!id ? id : 'default`
|
|
21
|
+
|
|
22
|
+
# Preferred TypeScript settings for modern projects
|
|
23
|
+
|
|
24
|
+
- `isolatedDeclarations: true`: USE ONLY FOR PUBLISHED LIBRARIES, enables faster declaration emit and requires explicit type annotations on exports
|
|
25
|
+
- In such case all exported functions and variables must have explicit type annotations:
|
|
26
|
+
- `strictNullChecks: true`: Null and undefined are distinct types
|
|
27
|
+
- `moduleResolution: "bundler"`
|
|
28
|
+
- `jsx: "react-jsx"`: Modern JSX transform (no React default import needed)
|
|
29
|
+
|
|
30
|
+
# File Structure
|
|
31
|
+
|
|
32
|
+
- One-time use functions should stay in the same file they are used
|
|
33
|
+
- If function is really large, then it can be extracted
|
|
34
|
+
- Organize code in files in this order:
|
|
35
|
+
1. Imports
|
|
36
|
+
2. Types/Interfaces
|
|
37
|
+
3. Constants
|
|
38
|
+
4. Helper functions (private)
|
|
39
|
+
5. Main exports (classes, functions, components)
|
|
40
|
+
|
|
41
|
+
# Functions
|
|
42
|
+
|
|
43
|
+
- Use arrow functions for:
|
|
44
|
+
- Short utility functions
|
|
45
|
+
- Callbacks
|
|
46
|
+
- Exported simple functions
|
|
47
|
+
- Use function declarations for:
|
|
48
|
+
- Complex functions with multiple statements
|
|
49
|
+
- Functions that need hoisting
|
|
50
|
+
- Named functions inside closures
|
|
51
|
+
- React Components
|
|
52
|
+
|
|
53
|
+
# Naming Conventions
|
|
54
|
+
|
|
55
|
+
- Use `camelCase` for variables and functions
|
|
56
|
+
- Use descriptive names that indicate purpose
|
|
57
|
+
- Prefix boolean variables with `is`, `has`, `can`, `should`
|
|
58
|
+
- Use `UPPER_SNAKE_CASE` for constants
|
|
59
|
+
- Use `export const UNUSED: unique symbol = Symbol('UNUSED');` for genuinely unique identifiers
|
|
60
|
+
- Use `PascalCase` for class names
|
|
61
|
+
- Use descriptive names ending with purpose: `TransformerMap`, `WorkerDialog`, `RespondersBase`
|
|
62
|
+
|
|
63
|
+
# Import/export
|
|
64
|
+
|
|
65
|
+
- Never use `index.ts` files for re-exporting unless specifically instructed or working with a published library with entrypoint
|
|
66
|
+
- Always use named exports `export function Foo()`
|
|
67
|
+
- Prefer not to use default exports if not necessary (like Storybook `meta`)
|
|
68
|
+
- Prefer path aliases: `@/src/foo/bar/file`
|
|
69
|
+
- Import siblings directly `./file.ts`
|
|
70
|
+
- Do not import more than one level up: `../file` OK, but not preferred
|
|
71
|
+
- NOT OK: more than one level `../../file` or stepping aside from parent dir `../dir/file`
|
|
72
|
+
- Order imports in this sequence, one blank line between groups (enforced and autofixed by `simple-import-sort`):
|
|
73
|
+
1. Polyfills — side-effect imports that must run first (`core-js`, `regenerator-runtime`, `whatwg-fetch`, `@vitest/web-worker`)
|
|
74
|
+
2. React (`react`, `react-dom`)
|
|
75
|
+
3. Third-party library imports (other packages, incl. `node:` builtins)
|
|
76
|
+
4. Local imports (path aliases `@/...`, then relative `./`, `../`)
|
|
77
|
+
5. CSS from libraries (e.g. `@heroui/react/styles`)
|
|
78
|
+
6. Local CSS (e.g. `./styles.css`)
|
|
79
|
+
- Side-effect imports (polyfills, CSS) are sorted into their group too; the linter only keeps the written order of multiple side-effect imports landing in the _same_ group, so sequence order-dependent ones yourself
|
|
80
|
+
|
|
81
|
+
# Type Annotation Patterns
|
|
82
|
+
|
|
83
|
+
- Use `interface` only for declaration merging/augmentation (e.g. extending a third-party global
|
|
84
|
+
interface) - a class can `implements` a `type` alias just as well, so that's not a reason to reach
|
|
85
|
+
for `interface`
|
|
86
|
+
- This is enforced by lint (`@typescript-eslint/consistent-type-definitions`), which can't special-case
|
|
87
|
+
augmentation - when it's genuinely needed, add
|
|
88
|
+
`// eslint-disable-next-line @typescript-eslint/consistent-type-definitions` above the `interface`
|
|
89
|
+
- Prefer to inline types into function signature or variable declarations
|
|
90
|
+
- Introduce types when reused or complex. Avoid creating a type for every single thing
|
|
91
|
+
- Try to reuse types that exist in project (e.g. redux state, zod schema, component props, final function signature can have one shared type + derivatives like `Omit<>`, `Partial<>` etc.)
|
|
92
|
+
- Use the `cause` option for error context `throw new Error('Unknown responder', { cause: ctx });`
|
|
93
|
+
- Use `//TODO` for later items and `//FIXME` for actionable more urgent items, no space after `//`
|
|
94
|
+
- When types are critical add type assertions, if super critical - runtime type assertions
|
|
95
|
+
- Prefer `as const` and `readonly` for immutable constants and objects
|
package/rules/vite.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: Set of rules for projects with Vite
|
|
4
|
+
paths:
|
|
5
|
+
- '**/vite.config.ts'
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
- Web Worker Polyfill `import '@vitest/web-worker';`
|
|
9
|
+
- In monorepo define root vitest project https://vitest.dev/guide/projects.html#defining-projects
|
|
10
|
+
|
|
11
|
+
# Prefer the shortest possible config definition
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from 'vite';
|
|
15
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
16
|
+
import react from '@vitejs/plugin-react';
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [react(), tailwindcss()],
|
|
20
|
+
});
|
|
21
|
+
```
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: always_apply
|
|
3
|
+
description: IDEA / WebStorm patterns
|
|
4
|
+
paths:
|
|
5
|
+
- '**/.idea/**/*.xml'
|
|
6
|
+
- '**/.idea/**/*.iml'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
**ALL** IDEA / WebStorm projects must adhere to policy unless explicitly prohibited.
|
|
10
|
+
|
|
11
|
+
Preserve already existing settings, add what's safe, ask user how to merge if there are conflicts.
|
|
12
|
+
|
|
13
|
+
# Configure `.idea/%projectName%.iml`
|
|
14
|
+
|
|
15
|
+
```xml
|
|
16
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
17
|
+
<module type="WEB_MODULE" version="4">
|
|
18
|
+
<component name="NewModuleRootManager">
|
|
19
|
+
<content url="file://$MODULE_DIR$">
|
|
20
|
+
<excludeFolder url="file://$MODULE_DIR$/.yarn" />
|
|
21
|
+
<excludePattern pattern=".turbo" />
|
|
22
|
+
<excludePattern pattern=".nx" />
|
|
23
|
+
<excludePattern pattern="build" />
|
|
24
|
+
<excludePattern pattern="coverage" />
|
|
25
|
+
<excludePattern pattern="dist" />
|
|
26
|
+
</content>
|
|
27
|
+
<orderEntry type="inheritedJdk" />
|
|
28
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
29
|
+
</component>
|
|
30
|
+
</module>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
# Configure `.idea/jsLibraryMappings.xml`
|
|
34
|
+
|
|
35
|
+
```xml
|
|
36
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
37
|
+
<project version="4">
|
|
38
|
+
<component name="JavaScriptLibraryMappings">
|
|
39
|
+
<includedPredefinedLibrary name="Node.js Core" />
|
|
40
|
+
</component>
|
|
41
|
+
</project>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
# Configure `.idea/prettier.xml`
|
|
45
|
+
|
|
46
|
+
```xml
|
|
47
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
48
|
+
<project version="4">
|
|
49
|
+
<component name="PrettierConfiguration">
|
|
50
|
+
<option name="myConfigurationMode" value="AUTOMATIC" />
|
|
51
|
+
<option name="myRunOnSave" value="true" />
|
|
52
|
+
<option name="myRunOnReformat" value="true" />
|
|
53
|
+
<option name="myFilesPattern" value="{**/*,*}.{js,jsx,ts,tsx,cjs,cts,mjs,mts,md,mdx,htm,html,vue,css,scss,sass,less,yml,yaml,json,json5,graphql,graphqls,xml}" />
|
|
54
|
+
</component>
|
|
55
|
+
</project>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
# Configure `.idea/jsLinters/eslint.xml`
|
|
59
|
+
|
|
60
|
+
```xml
|
|
61
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
62
|
+
<project version="4">
|
|
63
|
+
<component name="EslintConfiguration">
|
|
64
|
+
<files-pattern value="**/*.{js,jsx,ts,tsx,cjs,cts,mjs,mts,md,mdx,htm,html,vue}" />
|
|
65
|
+
<option name="fix-on-save" value="true" />
|
|
66
|
+
</component>
|
|
67
|
+
</project>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
# Configure `.idea/vcs.xml`
|
|
71
|
+
|
|
72
|
+
```xml
|
|
73
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
74
|
+
<project version="4">
|
|
75
|
+
<component name="CommitMessageInspectionProfile">
|
|
76
|
+
<profile version="1.0">
|
|
77
|
+
<inspection_tool class="BodyLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
|
78
|
+
<option name="RIGHT_MARGIN" value="100" />
|
|
79
|
+
</inspection_tool>
|
|
80
|
+
<inspection_tool class="SubjectBodySeparation" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
81
|
+
<inspection_tool class="SubjectLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
|
82
|
+
<option name="RIGHT_MARGIN" value="100" />
|
|
83
|
+
</inspection_tool>
|
|
84
|
+
</profile>
|
|
85
|
+
</component>
|
|
86
|
+
<component name="GitSharedSettings">
|
|
87
|
+
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
|
88
|
+
<list />
|
|
89
|
+
</option>
|
|
90
|
+
</component>
|
|
91
|
+
<component name="VcsDirectoryMappings">
|
|
92
|
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
93
|
+
</component>
|
|
94
|
+
</project>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
# GitIgnore
|
|
98
|
+
|
|
99
|
+
Folders defined in `.gitignore` should match with `.idea/%project_name%.iml` (usually only one IML file).
|
|
100
|
+
|
|
101
|
+
## Configure `.idea/.gitignore`:
|
|
102
|
+
|
|
103
|
+
```gitignore
|
|
104
|
+
# Default ignored files
|
|
105
|
+
/shelf/
|
|
106
|
+
/workspace.xml
|
|
107
|
+
# Editor-based HTTP Client requests
|
|
108
|
+
/httpRequests/
|
|
109
|
+
AugmentWebviewStateStore.xml
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
# Configure `.idea/codeStyles/codeStyleConfig.xml`
|
|
113
|
+
|
|
114
|
+
```xml
|
|
115
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
116
|
+
<state>
|
|
117
|
+
<option name="PREFERRED_PROJECT_CODE_STYLE" value="DiS" />
|
|
118
|
+
</state>
|
|
119
|
+
</component>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
# Configure `.idea/tailwindcss.xml`
|
|
123
|
+
|
|
124
|
+
Applies if project is using Tailwind.
|
|
125
|
+
|
|
126
|
+
```xml
|
|
127
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
128
|
+
<project version="4">
|
|
129
|
+
<component name="TailwindSettings">
|
|
130
|
+
<option name="lspConfiguration" value="{ "inspectPort": null, "emmetCompletions": false, "classAttributes": ["class", "className", "activeClassName", "disabledClassName", "ngClass", "class:list"], "classFunctions": [], "codeActions": true, "codeLens": true, "hovers": true, "suggestions": true, "validate": true, "colorDecorators": true, "rootFontSize": 16, "lint": { "cssConflict": "warning", "invalidApply": "error", "invalidScreen": "error", "invalidVariant": "error", "invalidConfigPath": "error", "invalidTailwindDirective": "error", "invalidSourceDirective": "error", "recommendedVariantOrder": "warning", "usedBlocklistedClass": "warning" }, "showPixelEquivalents": true, "includeLanguages": { "ftl": "html", "jinja": "html", "jinja2": "html", "smarty": "html", "tmpl": "gohtml", "cshtml": "html", "vbhtml": "html", "razor": "html" }, "files": { "exclude": [ "**/.git/**", "**/.hg/**", "**/.svn/**", "**/node_modules/**", "**/.yarn/**", "**/.venv/**", "**/venv/**", "**/.next/**", "**/.parcel-cache/**", "**/.svelte-kit/**", "**/.turbo/**", "**/__pycache__/**" ] }, "experimental": { "configFile": null, "classRegex": [ "Classes\\s*=\\s*['\"`]([^'\"`]*?)['\"`]", "['\"`]([^'\"`]*?)['\"`]", "Styles\\s*=\\s*['\"`]([^'\"`]*?)['\"`]", "['\"`]([^'\"`]*?)['\"`]" ] } }" />
|
|
131
|
+
</component>
|
|
132
|
+
</project>
|
|
133
|
+
```
|