Skip to content

feat(style): Introduce Prettier for automated code style enforcement#359

Draft
pgfeller wants to merge 2 commits into
openhab:mainfrom
pgfeller:pgfeller/issue334
Draft

feat(style): Introduce Prettier for automated code style enforcement#359
pgfeller wants to merge 2 commits into
openhab:mainfrom
pgfeller:pgfeller/issue334

Conversation

@pgfeller
Copy link
Copy Markdown
Contributor

@pgfeller pgfeller commented May 1, 2026

Summary

Resolves #334

Introduces Prettier as the automated code style formatter for this repository, along with pre-commit enforcement via Husky and lint-staged.

Changes

Tooling setup

  • .prettierrc — Prettier configuration: printWidth=120, tabWidth=4, singleQuote, semi=false, trailingComma: es5, LF line endings
  • .prettierignore — Excludes build outputs, node_modules, coverage reports, and generated/vendored files (openhab.tmLanguage.json, openhab-icon-theme.json)
  • .husky/pre-commit — Pre-commit hook that runs lint-staged
  • lint-staged config in package.json — runs prettier --write + eslint on staged TS/JS files; prettier --write on JSON/MD files
  • eslint-config-prettier — disables ESLint formatting rules that conflict with Prettier
  • New npm scripts: format, format:check, lint:fix

Formatter applied to existing files

All existing source files have been reformatted to bring the codebase into compliance with the new style rules.

Testing

The pre-commit hook was verified locally. All existing tests continue to pass (formatting-only changes, no logic affected).

Notes

  • Linting (eslint rule improvements) will be handled separately as mentioned in Introduce automated code style enforcement #334.
  • The Prettier config follows industry-standard defaults adjusted for this project's existing conventions (4-space indent, single quotes, no semicolons).

- Add .prettierrc configuration (printWidth=120, tabWidth=4, singleQuote,
  semi=false, trailingComma=es5, LF line endings)
- Add .prettierignore to exclude build outputs, node_modules, coverage,
  generated files, and vendored grammar/icon-theme files
- Add husky pre-commit hook running lint-staged
- Add lint-staged config: runs prettier --write + eslint on TS/JS files,
  prettier --write on JSON/MD files
- Add npm scripts: format, format:check, lint:fix
- Add eslint-config-prettier to disable ESLint rules that conflict with Prettier
- Apply Prettier formatting to all existing source files

Closes openhab#334

Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
@pgfeller pgfeller self-assigned this May 1, 2026
@pgfeller pgfeller added this to the 1.0.1 milestone May 1, 2026
@pgfeller pgfeller requested a review from a team May 1, 2026 01:52
@pgfeller pgfeller marked this pull request as ready for review May 1, 2026 02:04
Copilot AI review requested due to automatic review settings May 1, 2026 02:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces automated code formatting via Prettier (with pre-commit enforcement through Husky + lint-staged) and applies the formatter across the existing codebase to standardize style and reduce formatting-only review noise.

Changes:

  • Add Prettier configuration/ignore rules plus Husky + lint-staged pre-commit enforcement and formatting/lint scripts.
  • Reformat TS/JS/JSON/MD/CSS and workflow/config files to match the new style (4-space indent, single quotes, no semicolons, etc.).
  • Add CI jobs to check formatting and run ESLint.

Reviewed changes

Copilot reviewed 76 out of 97 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tsconfig.json Reformats TS project config to match Prettier JSON style.
snippets/openhab_sitemaps.json Reformats snippet JSON.
snippets/openhab_rules_typeconversions.json Reformats snippet JSON.
snippets/openhab_rules_designpattern.json Reformats snippet JSON.
snippets/openhab_rules.json Reformats snippet JSON (incl. whitespace cleanup).
snippets/openhab.json Normalizes line endings/formatting for snippet JSON.
shared.webpack.config.js Reformats shared webpack config to Prettier style.
serverJS/webpack.config.js Reformats server webpack config to Prettier style.
serverJS/src/Server.js Reformats language server implementation to Prettier style.
serverJS/src/LSPServer.js Reformats module export object (comma/trailing style).
serverJS/src/ItemCompletion/ItemCompletionProvider.js Reformats provider implementation; no intentional logic changes.
serverJS/src/ItemCompletion/Item.js Reformats Item model implementation.
serverJS/src/DocumentValidation/DocumentValidator.js Reformats validator module export formatting.
serverJS/package.json Reformats package metadata JSON.
serverJS/jest-unit.json Reformats Jest unit config JSON.
serverJS/jest-integration.json Reformats Jest integration config JSON.
serverJS/tests/unit/Server.test.js Reformats unit tests.
serverJS/tests/unit/LSPServer.test.js Reformats unit tests.
serverJS/tests/unit/ItemCompletion/Item.test.js Reformats unit tests.
serverJS/tests/unit/DocumentValidation/DocumentValidator.test.js Reformats unit tests.
serverJS/tests/integration/Server.test.js Reformats integration tests.
serverJS/tests/integration/LSPServer.test.js Reformats integration tests.
serverJS/tests/integration/ItemCompletion/ItemCompletionProvider.test.js Reformats integration tests.
serverJS/mocks/vscode-languageserver.js Reformats Jest mock module.
serverJS/mocks/Server.js Reformats Jest mock module.
serverJS/mocks/ItemCompletion/ItemCompletionProvider.js Reformats Jest mock module.
serverJS/mocks/DocumentValidation/DocumentValidator.js Reformats Jest mock module.
scripts/dev-help.js Reformats dev helper script output concatenation.
package.json Adds format/lint scripts, Husky/lint-staged/Prettier deps, lint-staged config, and view icons.
meta/language-configuration.json Reformats language configuration JSON.
docs/USAGE.md Reformats markdown (quotes/emphasis/escaping) to Prettier style.
client/webpack.config.js Reformats client webpack config.
client/tsconfig.test.json Reformats test TS config.
client/tsconfig.json Reformats client TS config.
client/src/extension.ts Reformats extension activation/commands wiring.
client/src/WebViews/media/vscode.css Reformats CSS to consistent indentation/quoting.
client/src/WebViews/media/updateNoticePanel.css Reformats CSS, including expanded selector formatting.
client/src/WebViews/media/reset.css Reformats CSS reset file.
client/src/WebViews/getNonce.ts Reformats nonce helper code style.
client/src/WebViews/UpdateNoticePanel.ts Reformats Update Notice webview panel code.
client/src/WebViews/PreviewPanel.ts Reformats preview webview panel code.
client/src/Utils/types.ts Reformats exported constants/objects.
client/src/Utils/Utils.ts Reformats utility functions and promise chains.
client/src/Utils/MigrationManager.ts Reformats migration helper logic.
client/src/Utils/ConfigManager.ts Reformats config manager implementation and event handler formatting.
client/src/ThingsExplorer/ThingsModel.ts Reformats model code and fetch promise chain formatting.
client/src/ThingsExplorer/ThingsExplorer.ts Reformats explorer tree provider.
client/src/ThingsExplorer/Thing.ts Reformats Thing wrapper class.
client/src/ThingsExplorer/ItemsProvider.ts Reformats snippet generation helpers/providers.
client/src/ThingsExplorer/IThing.ts Reformats TS interface declaration.
client/src/ThingsExplorer/IChannel.ts Reformats TS interface declaration.
client/src/ThingsExplorer/Channel.ts Reformats Channel wrapper class.
client/src/LanguageClient/RemoteLanguageClientProvider.ts Reformats remote LSP client provider.
client/src/LanguageClient/LocalLanguageClientProvider.ts Reformats local LSP client provider.
client/src/ItemsExplorer/SitemapPartialProvider.ts Reformats sitemap snippet provider.
client/src/ItemsExplorer/RuleProvider.ts Reformats rule snippet provider.
client/src/ItemsExplorer/ItemsModel.ts Reformats REST-backed items model.
client/src/ItemsExplorer/ItemsExplorer.ts Reformats items tree provider.
client/src/ItemsExplorer/ItemsCompletion.ts Reformats completion provider.
client/src/ItemsExplorer/Item.ts Reformats Item wrapper class.
client/src/ItemsExplorer/IItem.ts Reformats TS interface declaration.
client/src/HoverProvider/HoverProvider.ts Reformats hover provider logic and promise chains.
client/package.json Reformats client package JSON.
client/jest.config.js Reformats Jest config JS object formatting.
client/tests/tsconfig.json Reformats test TS config JSON.
client/tests/Utils.test.ts Reformats client unit tests.
client/tests/ThingsModel.test.ts Reformats client unit tests.
client/tests/ThingsExplorer.test.ts Reformats client unit tests.
client/tests/ItemsModel.test.ts Reformats client unit tests.
client/tests/ItemsExplorer.test.ts Reformats client unit tests.
client/tests/HoverProvider.test.ts Reformats client unit tests.
client/tests/ConfigManager.test.ts Reformats client unit tests.
client/mocks/vscode.ts Reformats VS Code API mock.
client/mocks/tsconfig.json Reformats mock TS config JSON.
client/mocks/ascii-table.ts Reformats mock module formatting.
README.md Reformats markdown and reference definitions.
CHANGELOG.md Normalizes line endings and formatting.
.vscode/tasks.json Reformats VS Code tasks JSON.
.vscode/settings.json Adds Prettier default formatter + format-on-save and reformats settings JSON.
.vscode/launch.json Reformats VS Code launch configurations.
.vscode/extensions.json Updates/reorders recommended extensions and reformats JSON.
.volta.json Reformats Volta config JSON.
.prettierrc Adds Prettier configuration.
.prettierignore Adds Prettier ignore rules for generated/build outputs and vendored files.
.markdownlint.json Minor formatting normalization.
.husky/pre-commit Adds pre-commit hook to run lint-staged.
.github/workflows/stale.yml Reformats workflow YAML indentation.
.github/workflows/ci.yml Reformats CI YAML and adds format + lint jobs.
.github/hooks/block-github-browser.json Reformats JSON hook configuration.
.github/ISSUE_TEMPLATE/feature_request.md Reformats markdown template spacing.
.github/ISSUE_TEMPLATE/bug_report.md Reformats markdown template spacing/lists.
.eslintrc.cjs Reformats ESLint config to match Prettier style.

Comment on lines +2 to +6
--container-paddding: 20px;
--input-padding-vertical: 6px;
--input-padding-horizontal: 4px;
--input-margin-vertical: 4px;
--input-margin-horizontal: 0;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Comment thread client/src/WebViews/UpdateNoticePanel.ts
Comment thread serverJS/package.json
Comment thread serverJS/src/ItemCompletion/ItemCompletionProvider.js
Comment thread client/src/Utils/types.ts
Comment thread docs/USAGE.md
- Remove deprecated husky v8 shebang from .husky/pre-commit; file now
  contains only 'npx lint-staged' as required by husky v9/v10
- Simplify cross-fork PR section in copilot-instructions.md: keep only
  repo-specific branch/fork naming; reference global github-pr-cli
  instructions for the general owner:branch rule

Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
@pgfeller pgfeller removed the refactor label May 1, 2026
@pgfeller pgfeller marked this pull request as draft May 16, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce automated code style enforcement

3 participants