Skip to content

Commit ccd6ea3

Browse files
Merge pull request #1 from devrail-dev/add-javascript-support
feat(javascript): add JavaScript/TypeScript standards page
2 parents 6072836 + bb25d86 commit ccd6ea3

File tree

2 files changed

+187
-14
lines changed

2 files changed

+187
-14
lines changed

content/docs/standards/_index.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Standards"
33
linkTitle: "Standards"
44
weight: 20
5-
description: "Per-language tooling standards for Python, Bash, Terraform, Ansible, Ruby, Go, and universal security tools."
5+
description: "Per-language tooling standards for Python, Bash, Terraform, Ansible, Ruby, Go, JavaScript/TypeScript, and universal security tools."
66
---
77

88
DevRail defines opinionated tooling standards for each supported language ecosystem. Every tool is pre-installed in the dev-toolchain container and invoked through consistent Makefile targets.
@@ -11,15 +11,15 @@ DevRail defines opinionated tooling standards for each supported language ecosys
1111

1212
The following table shows the default tool for each concern per language. These tools are pre-installed in the `dev-toolchain` container.
1313

14-
| Concern | Python | Bash | Terraform | Ansible | Ruby | Go |
15-
|---|---|---|---|---|---|---|
16-
| Linter | ruff | shellcheck | tflint | ansible-lint | rubocop, reek | golangci-lint |
17-
| Formatter | ruff format | shfmt | terraform fmt | -- | rubocop | gofumpt |
18-
| Security | bandit, semgrep | -- | tfsec, checkov | -- | brakeman, bundler-audit | govulncheck |
19-
| Tests | pytest | bats | terratest | molecule | rspec | go test |
20-
| Type Check | mypy | -- | -- | -- | sorbet | -- |
21-
| Docs | -- | -- | terraform-docs | -- | -- | -- |
22-
| Universal | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks |
14+
| Concern | Python | Bash | Terraform | Ansible | Ruby | Go | JavaScript |
15+
|---|---|---|---|---|---|---|---|
16+
| Linter | ruff | shellcheck | tflint | ansible-lint | rubocop, reek | golangci-lint | eslint |
17+
| Formatter | ruff format | shfmt | terraform fmt | -- | rubocop | gofumpt | prettier |
18+
| Security | bandit, semgrep | -- | tfsec, checkov | -- | brakeman, bundler-audit | govulncheck | npm audit |
19+
| Tests | pytest | bats | terratest | molecule | rspec | go test | vitest |
20+
| Type Check | mypy | -- | -- | -- | sorbet | -- | tsc |
21+
| Docs | -- | -- | terraform-docs | -- | -- | -- | -- |
22+
| Universal | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks | trivy, gitleaks |
2323

2424
A `--` entry means the concern does not apply to that language. Universal tools run for all projects regardless of declared languages.
2525

@@ -29,10 +29,10 @@ Each Makefile target runs the relevant tools for all languages declared in `.dev
2929

3030
| Target | What It Runs |
3131
|---|---|
32-
| `make lint` | ruff check, shellcheck, tflint, ansible-lint, mypy, rubocop, reek, golangci-lint |
33-
| `make format` | ruff format, shfmt, terraform fmt, rubocop, gofumpt |
34-
| `make test` | pytest, bats, terratest, molecule, rspec, go test |
35-
| `make security` | bandit, semgrep, tfsec, checkov, brakeman, bundler-audit, govulncheck |
32+
| `make lint` | ruff check, shellcheck, tflint, ansible-lint, mypy, rubocop, reek, golangci-lint, eslint, tsc |
33+
| `make format` | ruff format, shfmt, terraform fmt, rubocop, gofumpt, prettier |
34+
| `make test` | pytest, bats, terratest, molecule, rspec, go test, vitest |
35+
| `make security` | bandit, semgrep, tfsec, checkov, brakeman, bundler-audit, govulncheck, npm audit |
3636
| `make scan` | trivy, gitleaks (universal -- all projects) |
3737
| `make docs` | terraform-docs |
3838
| `make check` | All of the above in sequence |
@@ -45,6 +45,7 @@ Each Makefile target runs the relevant tools for all languages declared in `.dev
4545
- [Ansible Standards](/docs/standards/ansible/) -- ansible-lint, molecule
4646
- [Ruby Standards](/docs/standards/ruby/) -- rubocop, brakeman, bundler-audit, rspec, reek, sorbet
4747
- [Go Standards](/docs/standards/go/) -- golangci-lint, gofumpt, govulncheck, go test
48+
- [JavaScript Standards](/docs/standards/javascript/) -- eslint, prettier, npm audit, vitest, tsc
4849
- [Universal Security](/docs/standards/universal/) -- trivy, gitleaks
4950

5051
## Consistent Page Structure
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: "JavaScript"
3+
linkTitle: "JavaScript"
4+
weight: 35
5+
description: "JavaScript/TypeScript tooling standards: ESLint, Prettier, npm audit, Vitest, and tsc."
6+
---
7+
8+
JavaScript and TypeScript projects use ESLint for linting, Prettier for formatting, npm audit for security scanning, Vitest for testing, and tsc for type checking. A single `javascript` entry in `.devrail.yml` covers both languages.
9+
10+
## Tools
11+
12+
| Category | Tool | Purpose |
13+
|---|---|---|
14+
| Linter | ESLint v9 | JavaScript/TypeScript linter (flat config) |
15+
| Formatter | Prettier | Opinionated code formatter (JS/TS/JSON/CSS/MD) |
16+
| Security | npm audit | Scans `package-lock.json` for known vulnerabilities |
17+
| Tests | Vitest | Fast, ESM-native test runner (Jest-compatible API) |
18+
| Type Check | tsc --noEmit | TypeScript compiler (gated on `tsconfig.json`) |
19+
20+
All tools are pre-installed in the dev-toolchain container. Do not install them on the host.
21+
22+
## Configuration
23+
24+
### ESLint
25+
26+
Config file: `eslint.config.js` (flat config) at repository root.
27+
28+
```js
29+
// eslint.config.js -- DevRail JS/TS lint configuration
30+
import eslint from "@eslint/js";
31+
import tseslint from "typescript-eslint";
32+
33+
export default tseslint.config(
34+
eslint.configs.recommended,
35+
tseslint.configs.recommended,
36+
{
37+
ignores: ["node_modules/", "dist/", "build/", "coverage/"],
38+
}
39+
);
40+
```
41+
42+
For JavaScript-only projects (no TypeScript):
43+
44+
```js
45+
// eslint.config.js -- DevRail JS-only lint configuration
46+
import eslint from "@eslint/js";
47+
48+
export default [
49+
eslint.configs.recommended,
50+
{
51+
ignores: ["node_modules/", "dist/", "build/", "coverage/"],
52+
},
53+
];
54+
```
55+
56+
ESLint v9 uses flat config (`eslint.config.js`), not the legacy `.eslintrc` format. The `@eslint/js` and `typescript-eslint` packages are installed globally in the container so flat config imports resolve without project-local `node_modules`.
57+
58+
### Prettier
59+
60+
Config file: `.prettierrc` at repository root.
61+
62+
```json
63+
{
64+
"semi": true,
65+
"singleQuote": false,
66+
"trailingComma": "es5",
67+
"printWidth": 80,
68+
"tabWidth": 2
69+
}
70+
```
71+
72+
A `.prettierignore` file is required to exclude generated files:
73+
74+
```
75+
node_modules/
76+
dist/
77+
build/
78+
coverage/
79+
```
80+
81+
Prettier formats JS, TS, JSON, CSS, and Markdown files. The `.prettierignore` controls scope.
82+
83+
### TypeScript
84+
85+
Config file: `tsconfig.json` at repository root. When present, `tsc --noEmit` runs as part of `make lint`.
86+
87+
```json
88+
{
89+
"compilerOptions": {
90+
"target": "ES2022",
91+
"module": "ESNext",
92+
"moduleResolution": "bundler",
93+
"strict": true,
94+
"noEmit": true,
95+
"esModuleInterop": true,
96+
"skipLibCheck": true,
97+
"forceConsistentCasingInFileNames": true,
98+
"resolveJsonModule": true,
99+
"isolatedModules": true
100+
},
101+
"include": ["src"],
102+
"exclude": ["node_modules", "dist", "build"]
103+
}
104+
```
105+
106+
### Vitest
107+
108+
Config file: `vitest.config.ts` (or `vitest.config.js`) at repository root.
109+
110+
```ts
111+
import { defineConfig } from "vitest/config";
112+
113+
export default defineConfig({
114+
test: {
115+
globals: true,
116+
environment: "node",
117+
coverage: {
118+
reporter: ["text", "json", "html"],
119+
},
120+
},
121+
});
122+
```
123+
124+
## Makefile Targets
125+
126+
| Target | Command | Description |
127+
|---|---|---|
128+
| `make lint` | `eslint .` | Lint all JS/TS files |
129+
| `make lint` | `tsc --noEmit` | Type check (if `tsconfig.json` exists) |
130+
| `make format` | `prettier --check .` | Check formatting |
131+
| `make security` | `npm audit --audit-level=moderate` | Dependency vulnerability scanning (if `package-lock.json` exists) |
132+
| `make test` | `vitest run` | Run test suite (if `*.test.*` or `*.spec.*` files exist) |
133+
134+
## Pre-Commit Hooks
135+
136+
### Local Hooks (run on every commit, under 30 seconds)
137+
138+
ESLint and Prettier run on every commit to catch lint and formatting issues:
139+
140+
```yaml
141+
# .pre-commit-config.yaml -- JavaScript/TypeScript hooks
142+
repos:
143+
- repo: https://github.com/pre-commit/mirrors-eslint
144+
rev: v9.27.0
145+
hooks:
146+
- id: eslint
147+
additional_dependencies:
148+
- eslint
149+
- "@eslint/js"
150+
- typescript-eslint
151+
- typescript
152+
153+
- repo: https://github.com/pre-commit/mirrors-prettier
154+
rev: v4.0.0-alpha.8
155+
hooks:
156+
- id: prettier
157+
```
158+
159+
### CI-Only (too slow for local hooks)
160+
161+
- `npm audit --audit-level=moderate` -- dependency vulnerability scanning
162+
- `vitest run` -- full test suite
163+
164+
## Notes
165+
166+
- **Single `javascript` entry covers both JS and TS.** Do not add a separate `typescript` entry to `.devrail.yml`. TypeScript support auto-activates when `tsconfig.json` is present.
167+
- **ESLint v9 uses flat config.** The config file is `eslint.config.js` (not `.eslintrc`). The `@eslint/js` and `typescript-eslint` packages provide rule configurations for the flat config format.
168+
- **tsc runs under `make lint`, not a separate target.** Type checking is static analysis (like mypy for Python). It is gated on `tsconfig.json` presence.
169+
- **Prettier formats more than JS/TS.** Prettier handles JSON, CSS, Markdown, and other file types. Projects must use `.prettierignore` to exclude generated files.
170+
- **npm audit gates on `package-lock.json`.** If no `package-lock.json` exists, npm audit is skipped because there are no locked dependencies to scan.
171+
- **Vitest gates on test file presence.** If no `*.test.*` or `*.spec.*` files exist, vitest is skipped.
172+
- **All tools are pre-installed in the dev-toolchain container.** Do not install them on the host.

0 commit comments

Comments
 (0)