Skip to content

Conversation

Copy link

Copilot AI commented Oct 31, 2025

Adds pre-commit hooks and CI checks to enforce consistent formatting and linting across platforms, normalizing to LF line endings.

Changes

  • package.json: Added lint and prepare scripts, moved prettier to devDependencies, added lint-staged config with ESLint caching
  • eslint.config.js: ESLint 9 flat config extending eslint:recommended and prettier, with browser/Node/test globals
  • .husky/pre-commit: Runs lint-staged on staged files only
  • .github/workflows/ci-format-lint.yml: Checks format and lint on PR/push to all branches using ubuntu-24.04 runner (matching existing CI workflow)
  • .editorconfig: Enforces LF, UTF-8, 2-space indents across editors
  • .gitignore: Added .eslintcache

Note: .prettierrc.json and .gitattributes (LF enforcement) already existed with correct configuration.

Example

Pre-commit hook automatically formats and lints:

git commit -m "fix: update source"
# → lint-staged runs prettier --write and eslint --fix on staged files
# → commit proceeds with formatted code

CI workflow validates on push:

- name: Prettier check
  run: npm run format-check
- name: ESLint
  run: npm run lint

This pull request was created as a result of the following prompt from Copilot chat.

Goal
Add reliable, cross-platform formatting and linting enforcement to AR.js-core using Husky + lint-staged locally and a CI workflow that runs Prettier and ESLint on every PR/push. Normalize line endings to LF across platforms to avoid Windows vs Linux divergences. Keep existing scripts and builds intact.

Scope of changes

  1. package.json
  • Add scripts: "format", "format-check", "lint", and "prepare": "husky" (preserve existing scripts).
  • Add devDependencies: eslint, eslint-config-prettier, husky, lint-staged, prettier.
  • Move prettier from dependencies to devDependencies if currently listed under dependencies (to avoid shipping it at runtime).
  • Add lint-staged config: format staged files with Prettier and fix JS/TS with ESLint.
  1. Prettier configuration
  • Add .prettierrc.json with endOfLine: "lf" and standard style options.
  1. Editor/line-endings normalization
  • Add .editorconfig to align IDE defaults across contributors.
  • Add .gitattributes to enforce LF on text files and keep binaries untouched.
  1. Git hooks
  • Add .husky/pre-commit that runs lint-staged (fast, staged-only checks).
  1. ESLint config
  • Add a minimal .eslintrc.json extending eslint:recommended and prettier (to avoid rule conflicts with Prettier). No opinionated rules beyond recommended.
  1. CI workflow
  • Add .github/workflows/ci-format-lint.yml to run on pull_request and push (main, dev, and copilot/** branches). Steps: setup Node 20, npm ci, run format-check and lint.

Non-goals

  • Do not modify existing build, test, or example code other than formatting if required by Prettier.
  • Do not change webpack/vite configs.

Files to add/update

{
  "scripts": {
    "format": "prettier --write .",
    "format-check": "prettier --check .",
    "lint": "eslint .",
    "prepare": "husky"
  },
  "devDependencies": {
    "eslint": "^9.14.0",
    "eslint-config-prettier": "^9.1.0",
    "husky": "^9.1.7",
    "lint-staged": "15.4.3",
    "prettier": "^3.4.2"
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx,css,md,json}": [
      "prettier --write"
    ],
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix"
    ]
  }
}
{
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
  "semi": true,
  "arrowParens": "always",
  "endOfLine": "lf"
}
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
# Enforce LF on text files
*.js text eol=lf
*.mjs text eol=lf
*.cjs text eol=lf
*.ts text eol=lf
*.json text eol=lf
*.md text eol=lf
*.css text eol=lf
*.html text eol=lf

# Binary files untouched
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.webp binary
*.mp4 binary
*.mp3 binary
*.woff binary
*.woff2 binary
*.ttf binary
*.otf binary
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Only format and lint what's staged (fast)
npx lint-staged
{
  "root": true,
  "env": {
    "browser": true,
    "es2022": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "prettier"
  ],
  "parserOptions": {
    "ecmaVersion": 2022,
    "sourceType": "module"
  },
  "rules": {}
}
name: Format and Lint

on:
  pull_request:
  push:
    branches: [main, dev, "copilot/**"]

jobs:
  format-lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - name: Install
        run: npm ci

      - name: Prettier check
        run: npm run format-check

      - name: ESLint
        run: npm run lint

Notes

  • When updating package.json, preserve existing fields and scripts (dev, build, test, vite scripts, etc.). Only add the new scripts/sections or merge if keys already exist.
  • If prettier currently appears under dependencies, move it to devDependencies. Keep versions as defined above unless a newer compatible version is already present.
  • Ensure executable flag for .husky/pre-commit (chmod +x) after creation in the repo; Husky usually handles this when committed in Git.
  • CI workflow is additive and should not replace existing workflows.
Original prompt

Goal
Add reliable, cross-platform formatting and linting enforcement to AR.js-core using Husky + lint-staged locally and a CI workflow that runs Prettier and ESLint on every PR/push. Normalize line endings to LF across platforms to avoid Windows vs Linux divergences. Keep existing scripts and builds intact.

Scope of changes

  1. package.json
  • Add scripts: "format", "format-check", "lint", and "prepare": "husky" (preserve existing scripts).
  • Add devDependencies: eslint, eslint-config-prettier, husky, lint-staged, prettier.
  • Move prettier from dependencies to devDependencies if currently listed under dependencies (to avoid shipping it at runtime).
  • Add lint-staged config: format staged files with Prettier and fix JS/TS with ESLint.
  1. Prettier configuration
  • Add .prettierrc.json with endOfLine: "lf" and standard style options.
  1. Editor/line-endings normalization
  • Add .editorconfig to align IDE defaults across contributors.
  • Add .gitattributes to enforce LF on text files and keep binaries untouched.
  1. Git hooks
  • Add .husky/pre-commit that runs lint-staged (fast, staged-only checks).
  1. ESLint config
  • Add a minimal .eslintrc.json extending eslint:recommended and prettier (to avoid rule conflicts with Prettier). No opinionated rules beyond recommended.
  1. CI workflow
  • Add .github/workflows/ci-format-lint.yml to run on pull_request and push (main, dev, and copilot/** branches). Steps: setup Node 20, npm ci, run format-check and lint.

Non-goals

  • Do not modify existing build, test, or example code other than formatting if required by Prettier.
  • Do not change webpack/vite configs.

Files to add/update

{
  "scripts": {
    "format": "prettier --write .",
    "format-check": "prettier --check .",
    "lint": "eslint .",
    "prepare": "husky"
  },
  "devDependencies": {
    "eslint": "^9.14.0",
    "eslint-config-prettier": "^9.1.0",
    "husky": "^9.1.7",
    "lint-staged": "15.4.3",
    "prettier": "^3.4.2"
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx,css,md,json}": [
      "prettier --write"
    ],
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix"
    ]
  }
}
{
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
  "semi": true,
  "arrowParens": "always",
  "endOfLine": "lf"
}
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
# Enforce LF on text files
*.js text eol=lf
*.mjs text eol=lf
*.cjs text eol=lf
*.ts text eol=lf
*.json text eol=lf
*.md text eol=lf
*.css text eol=lf
*.html text eol=lf

# Binary files untouched
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.webp binary
*.mp4 binary
*.mp3 binary
*.woff binary
*.woff2 binary
*.ttf binary
*.otf binary
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Only format and lint what’s staged (fast)
npx lint-staged
{
  "root": true,
  "env": {
    "browser": true,
    "es2022": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "prettier"
  ],
  "parserOptions": {
    "ecmaVersion": 2022,
    "sourceType": "module"
  },
  "rules": {}
}
name: Format and Lint

on:
  pull_request:
  push:
    branches: [main, dev, "copilot/**"]

jobs:
  format-lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - name: Install
        run: npm ci

      - name: Prettier check
        run: npm run format-check

      - name: ESLint
        run: npm run lint

Notes

  • When updating package.json, preserve existing fields and scripts (dev, build, test, vite scripts, etc.). Only add the new scripts/sections or merge if keys already exist.
  • If prettier currently appears under dependencies, move it to devDependencies. Keep versions as defined above unless a newer compatible version is already present.
  • Ensure executable flag for .husky/pre-commit (chmod +x) after creation in the repo; Husky usually handles this when committed in Git.
  • CI workflow is additive and should not replace existing workflows.

This pull request was created as a result of the following prompt from Copilot chat.

Goal
Add reliable, cross-platform formatting and linting enforcement to AR.js-core using Husky + lint-staged locally and a CI workflow that runs Prettier and ESLint on every PR/push. Normalize line endings to LF across platforms to avoid Windows vs Linux divergences. Keep existing scripts and builds intact.

Scope of changes

  1. package.json
  • Add scripts: "format", "format-check", "lint", and "prepare": "husky" (preserve existing scripts).
  • Add devDependencies: eslint, eslint-config-prettier, husky, lint-staged, prettier.
  • Move prettier from dependencies to devDependencies if currently listed under dependencies (to avoid shipping it at runtime).
  • Add lint-staged config: format staged files with Prettier and fix JS/TS with ESLint.
  1. Prettier configuration
  • Add .prettierrc.json with endOfLine: "lf" and standard style options.
  1. Editor/line-endings normalization
  • Add .editorconfig to align IDE defaults across contributors.
  • Add .gitattributes to enforce LF on text files and keep binaries untouched.
  1. Git hooks
  • Add .husky/pre-commit that runs lint-staged (fast, staged-only checks).
  1. ESLint config
  • Add a minimal .eslintrc.json extending eslint:recommended and prettier (to avoid rule conflicts with Prettier). No opinionated rules beyond recommended.
  1. CI workflow
  • Add .github/workflows/ci-format-lint.yml to run on pull_request and push (main, dev, and copilot/** branches). Steps: setup Node 20, npm ci, run format-check and lint.

Non-goals

  • Do not modify existing build, test, or example code other than formatting if required by Prettier.
  • Do not change webpack/vite configs.

Files to add/update

{
  "scripts": {
    "format": "prettier --write .",
    "format-check": "prettier --check .",
    "lint": "eslint .",
    "prepare": "husky"
  },
  "devDependencies": {
    "eslint": "^9.14.0",
    "eslint-config-prettier": "^9.1.0",
    "husky": "^9.1.7",
    "lint-staged": "15.4.3",
    "prettier": "^3.4.2"
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx,css,md,json}": [
      "prettier --write"
    ],
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix"
    ]
  }
}
{
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
  "semi": true,
  "arrowParens": "always",
  "endOfLine": "lf"
}
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
# Enforce LF on text files
*.js text eol=lf
*.mjs text eol=lf
*.cjs text eol=lf
*.ts text eol=lf
*.json text eol=lf
*.md text eol=lf
*.css text eol=lf
*.html text eol=lf

# Binary files untouched
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.webp binary
*.mp4 binary
*.mp3 binary
*.woff binary
*.woff2 binary
*.ttf binary
*.otf binary
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Only format and lint what’s staged (fast)
npx lint-staged
{
  "root": true,
  "env": {
    "browser": true,
    "es2022": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "prettier"
  ],
  "parserOptions": {
    "ecmaVersion": 2022,
    "sourceType": "module"
  },
  "rules": {}
}
name: Format and Lint

on:
  pull_request:
  push:
    branches: [main, dev, "copilot/**"]

jobs:
  format-lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - name: Install
        run: npm ci

      - name: Prettier check
        run: npm run format-check

      - name: ESLint
        run: npm run lint

Notes

  • When updating package.json, preserve existing fields and scripts (dev, build, test, vite scripts, etc.). Only add the new scripts/sections or merge if keys already exist.
  • If prettier currently appears under dependencies, move it to devDependencies. Keep versions as defined above unless a newer compatible version is already present.
  • Ensure executable flag for .husky/pre-commit (chmod +x) after creation in the repo; Husky usually handles this when committed in Git.
  • CI workflow is additive and should not replace existing workflows.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits October 31, 2025 14:10
…ement

Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Copilot AI changed the title [WIP] Add reliable formatting and linting enforcement to AR.js-core Add Husky + lint-staged + ESLint with CI enforcement Oct 31, 2025
Copilot AI requested a review from kalwalt October 31, 2025 14:20
Copilot finished work on behalf of kalwalt October 31, 2025 14:20
@kalwalt kalwalt marked this pull request as ready for review October 31, 2025 14:35
Co-authored-by: kalwalt <1275858+kalwalt@users.noreply.github.com>
Copilot AI requested a review from kalwalt October 31, 2025 14:40
Copilot finished work on behalf of kalwalt October 31, 2025 14:40
@kalwalt kalwalt merged commit c0d8888 into copilot/add-ecs-architecture-and-plugins Oct 31, 2025
4 checks passed
@kalwalt kalwalt added enhancement New feature or request javascript labels Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request javascript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants