Skip to content

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Apr 8, 2025

close #384
close #376
close #278
close #429
close #398


Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced Dockerfile formatting support via a new configuration option, enabling fallback formatting with an alternative engine.
    • Added new Dockerfiles with various configurations and environment variables for testing.
  • Documentation

    • Enhanced guidance detailing how to enable Dockerfile formatting and outlining limitations with ignore files.
  • Refactor & Testing

    • Improved error handling and stability during formatting.
    • Streamlined plugin usage and updated tests to validate the new Dockerfile support.

These updates provide a smoother experience when working with Dockerfiles and improve overall formatting reliability.

@JounQin JounQin requested a review from Copilot April 8, 2025 07:39
Copy link

changeset-bot bot commented Apr 8, 2025

🦋 Changeset detected

Latest commit: 00df081

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
prettier-plugin-sh Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Apr 8, 2025

Walkthrough

The pull request integrates Dockerfile formatting into the shell plugin by introducing a fallback printer using dockerfmt, enabled via the parser: dockerfile option. It updates documentation to clarify Dockerfile and ignore file support, revises dependency versions, and refactors core parser and printer exports along with error handling. Test files and scripts are modified to accommodate namespace imports and updated error types. Additional Dockerfile fixtures along with a new TypeScript declaration for prettier-plugin-ini are also included.

Changes

File(s) Summary
.changeset/tiny-ghosts-press.md Added entry documenting the fallback printer feature via dockerfmt and the option parser: dockerfile.
packages/sh/README.md Enhanced documentation for Dockerfile parsing improvements and detailed guidelines for enabling dockerfmt; retained warnings on ignore file limitations.
packages/sh/package.json Upgraded sh-syntax dependency (^0.5.4 → ^0.5.6) and added a new dependency @reteps/dockerfmt.
packages/sh/src/index.ts Refactored exports by replacing ShPlugin with separate dockerfileParser/dockerPrinter and shParser/shPrinter; introduced new interfaces and improved error handling.
packages/sh/test/{error.spec.ts,fixtures.spec.ts,parser.spec.ts} Updated tests to use namespace imports from prettier-plugin-sh, revised error types (e.g., SyntaxErrorParseError), and adjusted function references.
packages/sh/test/fixtures/{376.Dockerfile,384.Dockerfile,398.Dockerfile} Added new Dockerfile fixtures illustrating various scenarios: command iterations, maintainer declaration, and environment variable settings.
packages/sh/test/shim.d.ts Added a new TypeScript declaration file for the prettier-plugin-ini module.
scripts/format.ts Modified import statements to consolidate plugin imports (using pkg and a namespace import sh) in the Prettier configuration.
scripts/languages.ts Updated the getSupportedLanguages function to use default parameters and adjusted language support for the 'sh' parser.
test.js Introduced a new test file that imports and demonstrates the usage of formatDockerfile from @reteps/dockerfmt, logging the formatted result.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/Prettier Request
    participant P as Parser (dockerfileParser)
    participant E as Error Cache
    participant D as Docker Printer (dockerPrinter)
    participant F as dockerfmt Formatter

    U->>P: Submit Dockerfile content (using parser: dockerfile)
    P->>P: Attempt to parse using shell parser
    alt Parsing fails
      P->>E: Cache error details
      P->>D: Trigger fallback printer
      D->>F: Format content with dockerfmt
      F-->>D: Return formatted output
    else Parsing succeeds
      P->>P: Continue normal processing
    end
    D-->>U: Return formatted Dockerfile output
Loading

Assessment against linked issues

Objective Addressed Explanation
Dockerfile with MAINTAINER email fails parsing (#384)
Dockerfile/Containerfile formatting issues with for loops/semicolons (#376)
Suggestion for Dockerfile formatter bindings (#429)
SyntaxError: "foo(" must be followed by ) (#278) The issue regarding parentheses is not addressed.

Possibly related PRs

Poem

Oh, I’m a bunny, leaping through code,
With Dockerfmt magic on this new road,
Parsing and printing in a charming duet,
In every line, a joyful vignette,
My whiskers twitch with every new function,
Celebrating changes with bunny affection!
🐇 Hop, hop—code’s our true confection!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/sh/test/fixtures.spec.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6c12c1 and 9326c33.

⛔ Files ignored due to path filters (1)
  • packages/sh/test/__snapshots__/fixtures.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • packages/sh/test/fixtures.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/sh/test/fixtures.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codesandbox-ci bot commented Apr 8, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

@Copilot 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.

Copilot reviewed 7 out of 12 changed files in this pull request and generated no comments.

Files not reviewed (5)
  • packages/sh/package.json: Language not supported
  • packages/sh/test/snapshots/fixtures.spec.ts.snap: Language not supported
  • packages/sh/test/fixtures/376.Dockerfile: Language not supported
  • packages/sh/test/fixtures/384.Dockerfile: Language not supported
  • packages/sh/test/fixtures/398.Dockerfile: Language not supported
Comments suppressed due to low confidence (3)

scripts/languages.ts:41

  • The default assignment for 'aceModes' as [parser] may override custom passed values unexpectedly. Confirm that this aligns with the intended behavior.
  aceModes: string[] = [parser],

scripts/languages.ts:129

  • Removing the explicit aceModes array for 'toml' might cause inconsistencies in supported modes. Ensure that the default value produces the expected outcome.
    [...getSupportedLanguages('toml')],

packages/sh/src/index.ts:9

  • [nitpick] Renaming 'ShPrintOptions' to 'ShFormatOptions' may be confusing. Consider using a more descriptive alias or retaining the original name for clarity.
  type ShPrintOptions as ShFormatOptions,

Copy link

codecov bot commented Apr 8, 2025

Codecov Report

Attention: Patch coverage is 67.27273% with 18 lines in your changes missing coverage. Please review.

Project coverage is 80.72%. Comparing base (f7e38ae) to head (9326c33).

Files with missing lines Patch % Lines
packages/sh/src/index.ts 67.27% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #432      +/-   ##
==========================================
- Coverage   88.55%   80.72%   -7.83%     
==========================================
  Files          10       10              
  Lines         166      192      +26     
  Branches       45       51       +6     
==========================================
+ Hits          147      155       +8     
- Misses         18       36      +18     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

pkg-pr-new bot commented Apr 8, 2025

Open in StackBlitz

prettier-plugin-autocorrect

npm i https://pkg.pr.new/prettier-plugin-autocorrect@432

prettier-plugin-pkg

npm i https://pkg.pr.new/prettier-plugin-pkg@432

prettier-plugin-sh

npm i https://pkg.pr.new/prettier-plugin-sh@432

prettier-plugin-sql

npm i https://pkg.pr.new/prettier-plugin-sql@432

prettier-plugin-toml

npm i https://pkg.pr.new/prettier-plugin-toml@432

commit: 7019758

Copy link
Contributor

github-actions bot commented Apr 8, 2025

size-limit report 📦

Path Size
packages/autocorrect/lib/index.js 538 B (0%)
packages/pkg/lib/index.js 447 B (0%)
packages/sh/lib/index.js 3.24 KB (0%)
packages/sql/lib/index.js 2.4 KB (0%)

Copy link
Contributor

github-actions bot commented Apr 8, 2025

Deploy preview for prettier ready!

✅ Preview
https://prettier-83a8fx1zc-1stg.vercel.app

Built with commit 00df081.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

github-actions bot commented Apr 8, 2025

📊 Package size report   No changes

File Before After
Total (Includes all files) 3.0 MB 3.0 MB
Tarball size 1.1 MB 1.1 MB
Unchanged files
File Size
.changeset/config.json 313 B
.changeset/README.md 510 B
.changeset/spotty-beds-applaud.md 189 B
.changeset/tiny-ghosts-press.md 159 B
.codesandbox/ci.json 38 B
.editorconfig 161 B
.gitattributes 152 B
.github/workflows/autofix.yml 920 B
.github/workflows/ci.yml 1.1 kB
.github/workflows/pkg-pr-new.yml 686 B
.github/workflows/pkg-size.yml 542 B
.github/workflows/release.yml 1.2 kB
.github/workflows/size-limit.yml 633 B
.github/workflows/vercel.yml 901 B
.lintstagedrc.js 48 B
.nvmrc 6 B
.postcssrc.cjs 51 B
.prettierignore 23 B
.prettierrc 24 B
.remarkrc 159 B
.renovaterc 49 B
.simple-git-hooks.js 49 B
.size-limit.json 292 B
.yarn/plugins/plugin-prepare-lifecycle.cjs 202 B
.yarn/releases/yarn-4.8.1.cjs 2.8 MB
.yarnrc.yml 397 B
assets/pkg.svg 15.1 kB
assets/sh.png 14.4 kB
CHANGELOG.md 393 B
docs/App.tsx 1.2 kB
docs/global.css 321 B
docs/index.tsx 211 B
eslint.config.js 516 B
index.html 414 B
LICENSE 1.1 kB
package.json 3.4 kB
packages/autocorrect/CHANGELOG.md 1.9 kB
packages/autocorrect/index.d.cts 63 B
packages/autocorrect/LICENSE 1.1 kB
packages/autocorrect/package.json 1.2 kB
packages/autocorrect/README.md 3.9 kB
packages/autocorrect/src/index.ts 1.4 kB
packages/autocorrect/src/types.ts 78 B
packages/autocorrect/test/__snapshots__/fixtures.spec.ts.snap 4.7 kB
packages/autocorrect/test/fixtures.spec.ts 983 B
packages/autocorrect/test/fixtures/test.css 189 B
packages/autocorrect/test/fixtures/test.go 470 B
packages/autocorrect/test/fixtures/test.html 1.1 kB
packages/autocorrect/test/fixtures/test.md 1.1 kB
packages/autocorrect/test/fixtures/test.py 368 B
packages/autocorrect/test/fixtures/test.rb 234 B
packages/autocorrect/test/fixtures/test0.js 453 B
packages/autocorrect/tsconfig.json 154 B
packages/pkg/CHANGELOG.md 11.4 kB
packages/pkg/index.d.cts 47 B
packages/pkg/LICENSE 16.7 kB
packages/pkg/package.json 1.1 kB
packages/pkg/README.md 6.2 kB
packages/pkg/src/index.ts 1.4 kB
packages/pkg/src/rules/files.ts 1.7 kB
packages/pkg/src/rules/object.ts 899 B
packages/pkg/src/rules/sort.ts 2.4 kB
packages/pkg/src/types.ts 1.0 kB
packages/pkg/src/utils.ts 567 B
packages/pkg/test/__snapshots__/engines.spec.ts.snap 158 B
packages/pkg/test/__snapshots__/files.spec.ts.snap 173 B
packages/pkg/test/__snapshots__/test.spec.ts.snap 2.0 kB
packages/pkg/test/engines.spec.ts 417 B
packages/pkg/test/files.spec.ts 409 B
packages/pkg/test/fixtures/fixture1.json 1.0 kB
packages/pkg/test/fixtures/fixture2.json 863 B
packages/pkg/test/fixtures/fixture3.json 430 B
packages/pkg/test/test.spec.ts 2.3 kB
packages/pkg/tsconfig.json 154 B
packages/sh/CHANGELOG.md 13.2 kB
packages/sh/index.d.cts 45 B
packages/sh/LICENSE 1.1 kB
packages/sh/package.json 1.5 kB
packages/sh/README.md 10.9 kB
packages/sh/src/index.ts 12.5 kB
packages/sh/test/__snapshots__/fixtures.spec.ts.snap 232 B
packages/sh/test/__snapshots__/shellscript.spec.ts.snap 394 B
packages/sh/test/error.spec.ts 502 B
packages/sh/test/fixtures.spec.ts 1.5 kB
packages/sh/test/fixtures/.dockerignore 108 B
packages/sh/test/fixtures/.nvmrc 6 B
packages/sh/test/fixtures/.properties 177 B
packages/sh/test/fixtures/133.sh 5.2 kB
packages/sh/test/fixtures/146.ini 1.1 kB
packages/sh/test/fixtures/147.cfg 3.3 kB
packages/sh/test/fixtures/148.ini 3.1 kB
packages/sh/test/fixtures/162.sh 15.7 kB
packages/sh/test/fixtures/182.sh 1.9 kB
packages/sh/test/fixtures/191.sh 1.7 kB
packages/sh/test/fixtures/278.Dockerfile 32 B
packages/sh/test/fixtures/292.Dockerfile 95 B
packages/sh/test/fixtures/376.Dockerfile 217 B
packages/sh/test/fixtures/384.Dockerfile 51 B
packages/sh/test/fixtures/398.Dockerfile 64 B
packages/sh/test/fixtures/Dockerfile 394 B
packages/sh/test/fixtures/hosts 406 B
packages/sh/test/fixtures/jvm.options 162 B
packages/sh/test/fixtures/no-ext 37 B
packages/sh/test/fixtures/shell.sh 368 B
packages/sh/test/parser.spec.ts 2.1 kB
packages/sh/tsconfig.json 154 B
packages/sql/CHANGELOG.md 11.3 kB
packages/sql/index.d.cts 47 B
packages/sql/LICENSE 1.1 kB
packages/sql/package.json 1.4 kB
packages/sql/README.md 6.9 kB
packages/sql/shim.d.ts 59 B
packages/sql/src/index.ts 13.0 kB
packages/sql/test/__snapshots__/fixtures-eol.spec.ts.snap 756 B
packages/sql/test/__snapshots__/fixtures.spec.ts.snap 2.0 kB
packages/sql/test/__snapshots__/sql.spec.ts.snap 374 B
packages/sql/test/fixtures-eol.spec.ts 1.3 kB
packages/sql/test/fixtures-eol/556.sql 73 B
packages/sql/test/fixtures-eol/557.sql 69 B
packages/sql/test/fixtures-eol/558.sql 69 B
packages/sql/test/fixtures-eol/559.sql 73 B
packages/sql/test/fixtures.spec.ts 1.7 kB
packages/sql/test/fixtures/144.sql 68 B
packages/sql/test/fixtures/233.sql 68 B
packages/sql/test/fixtures/277.sql 88 B
packages/sql/test/fixtures/279.sql 106 B
packages/sql/test/fixtures/291.sql 1.2 kB
packages/sql/test/fixtures/334.sql 15 B
packages/sql/test/fixtures/basic.sql 120 B
packages/sql/test/sql.spec.ts 660 B
packages/sql/tsconfig.json 154 B
packages/toml/CHANGELOG.md 2.0 kB
packages/toml/index.d.cts 49 B
packages/toml/LICENSE 1.1 kB
packages/toml/package.json 1.2 kB
packages/toml/README.md 5.2 kB
packages/toml/src/index.ts 1.3 kB
packages/toml/src/options.ts 2.6 kB
packages/toml/src/types.ts 381 B
packages/toml/test/__snapshots__/fixtures.spec.ts.snap 487 B
packages/toml/test/fixtures.spec.ts 955 B
packages/toml/test/fixtures/comments.toml 87 B
packages/toml/test/fixtures/fixture1.toml 162 B
packages/toml/tsconfig.json 154 B
README.md 6.8 kB
scripts/format.ts 593 B
scripts/languages.ts 2.9 kB
test.js 184 B
test/global.d.ts 41 B
test/tsconfig.json 223 B
tsconfig.base.json 89 B
tsconfig.json 275 B
vercel.json 229 B
vite.config.ts 544 B
vitest.config.ts 541 B

🤖 This report was automatically generated by pkg-size-action

@JounQin JounQin marked this pull request as ready for review April 8, 2025 09:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (3)
packages/sh/test/fixtures/384.Dockerfile (1)

1-2: ⚠️ Potential issue

Instruction Order & Deprecation Warning for MAINTAINER

The Dockerfile begins with the MAINTAINER instruction. Note that:

  • Dockerfile instructions should start with FROM, ARG, or a comment.
  • MAINTAINER is deprecated; it is recommended to use a LABEL instead (e.g., LABEL maintainer="Jean Luc Picard <picardj@starfleet.gov>").

If this fixture is used for testing dockerfmt behavior, consider adding a comment or a dummy FROM line at the very top to comply with best practices and to avoid Hadolint errors.

🧰 Tools
🪛 Hadolint (2.12.0)

[error] 1-1: Invalid instruction order. Dockerfile must begin with FROM, ARG or comment.

(DL3061)


[error] 1-1: MAINTAINER is deprecated

(DL4000)

packages/sh/test/fixtures/398.Dockerfile (1)

1-8: ⚠️ Potential issue

Dockerfile Instruction Order Issue

This Dockerfile starts directly with an ENV instruction, which can trigger Hadolint errors expecting a FROM, ARG, or comment at the top.
If this file is solely used as a test fixture for Dockerfile formatting, consider adding a dummy FROM or a leading comment to comply with Dockerfile best practices without affecting the intent of your tests.

🧰 Tools
🪛 Hadolint (2.12.0)

[error] 1-1: Invalid instruction order. Dockerfile must begin with FROM, ARG or comment.

(DL3061)

packages/sh/test/fixtures.spec.ts (1)

37-49: 💡 Verification agent

🧩 Analysis chain

Added Dockerfile-specific formatting test with proper error handling.

This section adds a new test case specifically for Dockerfile formatting using the new 'dockerfile' parser. However, there's a snapshot mismatch in the test pipeline.


🏁 Script executed:

#!/bin/bash
# Check what's causing the snapshot mismatch for "147.cfg 2"

# First, check if the fixture file exists
ls -la packages/sh/test/fixtures/147.cfg

# Then, see how it's being formatted with both parsers
cat packages/sh/test/fixtures/147.cfg

# Check the existing snapshot file to see what's expected
find packages/sh/test -name "*.snap" -type f -exec grep -l "147.cfg 2" {} \; | xargs cat

Length of output: 3560


Critical: Dockerfile Test Snapshot Mismatch Needs Resolution

The new Dockerfile formatting test in packages/sh/test/fixtures.spec.ts (lines 37–49) is still causing a snapshot mismatch for fixture 147.cfg (expected snapshot labeled with "147.cfg 2"). The shell output confirms that the fixture file exists and contains the expected metadata content, yet the formatted output or caught error (formatted error message from the new dockerfile parser) does not match the stored snapshot.

Please verify whether the change in output is the intended behavior. If so, update the snapshot accordingly; otherwise, adjust the formatting or error handling logic within the test to align with the expected snapshot output.

🧹 Nitpick comments (4)
test.js (1)

1-9: Top-Level Await and Error Handling

The use of top-level await is acceptable if your Node.js environment supports ES modules; ensure that the runtime is configured accordingly.
Additionally, consider adding error handling (e.g., a try-catch block) around the asynchronous call to gracefully handle any formatting errors during execution.

.changeset/tiny-ghosts-press.md (1)

1-6: Changeset Entry Formatting Review

The changeset entry clearly documents the new fallback printer feature using dockerfmt. Double-check that the use of backticks around printer and parser: dockerfile is consistent with your project’s style guidelines.

packages/sh/README.md (1)

38-39: Updated documentation for ignore files limitations.

The clarification about limited support for ignore files is helpful. Note that there's a minor style suggestion from static analysis.

Consider changing "can not" to "cannot" for better readability:

-    We can not do much on our side. See also <https://github.com/un-ts/prettier/issues/336>.
+    We cannot do much on our side. See also <https://github.com/un-ts/prettier/issues/336>.
🧰 Tools
🪛 LanguageTool

[style] ~39-~39: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...cases can be handled correctly. > We can not do much on our side. See also <https://...

(CAN_NOT_PREMIUM)

packages/sh/src/index.ts (1)

118-118: Potential memory growth in errorCache.
Storing parse errors in a global map could lead to unbounded memory usage if the plugin processes many files. Consider bounding or pruning this map.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7e38ae and 610865b.

⛔ Files ignored due to path filters (2)
  • packages/sh/test/__snapshots__/fixtures.spec.ts.snap is excluded by !**/*.snap
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (14)
  • .changeset/tiny-ghosts-press.md (1 hunks)
  • packages/sh/README.md (2 hunks)
  • packages/sh/package.json (1 hunks)
  • packages/sh/src/index.ts (2 hunks)
  • packages/sh/test/error.spec.ts (1 hunks)
  • packages/sh/test/fixtures.spec.ts (2 hunks)
  • packages/sh/test/fixtures/376.Dockerfile (1 hunks)
  • packages/sh/test/fixtures/384.Dockerfile (1 hunks)
  • packages/sh/test/fixtures/398.Dockerfile (1 hunks)
  • packages/sh/test/parser.spec.ts (1 hunks)
  • packages/sh/test/shim.d.ts (1 hunks)
  • scripts/format.ts (2 hunks)
  • scripts/languages.ts (3 hunks)
  • test.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/sh/test/parser.spec.ts (1)
packages/sh/src/index.ts (1)
  • parsers (221-224)
🪛 Hadolint (2.12.0)
packages/sh/test/fixtures/384.Dockerfile

[error] 1-1: Invalid instruction order. Dockerfile must begin with FROM, ARG or comment.

(DL3061)


[error] 1-1: MAINTAINER is deprecated

(DL4000)

packages/sh/test/fixtures/398.Dockerfile

[error] 1-1: Invalid instruction order. Dockerfile must begin with FROM, ARG or comment.

(DL3061)

🪛 GitHub Check: Lint and Test with Node.js 22 on ubuntu-latest
packages/sh/test/fixtures.spec.ts

[failure] 26-26: packages/sh/test/fixtures.spec.ts > parser and printer > should format all fixtures
Error: Snapshot parser and printer > should format all fixtures > 147.cfg 2 mismatched
❯ packages/sh/test/fixtures.spec.ts:26:58

🪛 GitHub Actions: CI
packages/sh/test/fixtures.spec.ts

[error] 26-26: Snapshot parser and printer > should format all fixtures > 147.cfg 2 mismatched

🪛 LanguageTool
packages/sh/README.md

[style] ~39-~39: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...cases can be handled correctly. > We can not do much on our side. See also <https://...

(CAN_NOT_PREMIUM)

🪛 GitHub Check: codecov/patch
packages/sh/src/index.ts

[warning] 93-94: packages/sh/src/index.ts#L93-L94
Added lines #L93 - L94 were not covered by tests


[warning] 109-109: packages/sh/src/index.ts#L109
Added line #L109 was not covered by tests


[warning] 183-183: packages/sh/src/index.ts#L183
Added line #L183 was not covered by tests


[warning] 216-216: packages/sh/src/index.ts#L216
Added line #L216 was not covered by tests

🔇 Additional comments (34)
packages/sh/test/shim.d.ts (1)

1-8: TypeScript Declaration File – Looks Good

The declaration for the module 'prettier-plugin-ini' is correctly defined, importing the Plugin type from prettier and exporting the constant ini as default.

packages/sh/test/fixtures/376.Dockerfile (1)

1-14: Good test fixture for Dockerfile formatting

This Dockerfile demonstrates both single-line and heredoc multi-line formatting styles for the same shell commands, which makes it an excellent test case for the formatter. The use of set -eux in both formats shows proper error handling practices in Docker scripts.

packages/sh/test/parser.spec.ts (2)

4-4: Appropriate import refactoring

The direct import of parsers aligns with the updated module structure that now exports parsers and printers separately.


7-7: Updated reference to hasPragma

This change properly references the hasPragma function through the new parsers export structure, maintaining the same functionality while simplifying the access pattern.

packages/sh/package.json (2)

53-53: Added dependency for Dockerfile formatting

The addition of @reteps/dockerfmt provides the necessary functionality for Dockerfile formatting. This aligns with the PR objective of using dockerfmt as a fallback formatter.


54-54: Updated sh-syntax dependency

Upgrading to sh-syntax version 0.5.6 likely provides necessary support for the error handling changes seen in other files.

packages/sh/test/error.spec.ts (4)

2-2: Improved error specificity

The explicit import of ParseError from sh-syntax provides more specific error handling capabilities.


4-4: Updated import pattern

This change appropriately imports all exports from the plugin, accommodating the restructured plugin exports.


12-12: Updated plugin reference

This change correctly updates the plugins array to use the new import name.


15-15: Enhanced error type checking

The test now expects the more specific ParseError type from sh-syntax rather than a generic SyntaxError, which better reflects the actual error handling in the updated implementation.

scripts/format.ts (2)

6-7: Import statement updated to support the new module structure.

The change from default imports to namespace imports for the prettier-plugin-sh module aligns with the PR objective of supporting dockerfmt as a fallback formatter.


21-21: Updated plugin references to match the new import structure.

This change correctly utilizes the new import references for the plugins array.

packages/sh/test/fixtures.spec.ts (3)

6-6: Import statement modified to support the new module structure.

Updated the import to use namespace import, which is consistent with other files in this PR.


21-22: Updated plugin reference to match the new import structure.

This change correctly uses the imported namespace for the plugins array.


23-35: Enhanced error handling and conditionally process Dockerfile files.

Good addition of error handling for formatting operations and conditional processing based on file type.

🧰 Tools
🪛 GitHub Check: Lint and Test with Node.js 22 on ubuntu-latest

[failure] 26-26: packages/sh/test/fixtures.spec.ts > parser and printer > should format all fixtures
Error: Snapshot parser and printer > should format all fixtures > 147.cfg 2 mismatched
❯ packages/sh/test/fixtures.spec.ts:26:58

🪛 GitHub Actions: CI

[error] 26-26: Snapshot parser and printer > should format all fixtures > 147.cfg 2 mismatched

packages/sh/README.md (2)

20-36: Enhanced documentation for Dockerfile support.

Good addition of detailed information about the improved Dockerfile support using dockerfmt with clear configuration examples.


262-262: Added link to dockerfmt repository.

Good addition of the reference to the dockerfmt project.

scripts/languages.ts (3)

41-41: Added default parameter value to simplify function calls.

Good enhancement by adding a default value for the aceModes parameter, which simplifies function calls.


95-95: Updated supported modes for the 'sh' parser.

The supported modes for the 'sh' parser now include 'properties' alongside 'dockerfile', 'gitignore', and 'sh', which aligns with the enhanced functionality.


129-129: Simplified function call by leveraging default parameter.

The call to getSupportedLanguages for 'toml' has been simplified by using the newly added default parameter value.

packages/sh/src/index.ts (14)

1-2: No immediate concerns.
These imports align well with the new Dockerfile formatting functionality.


9-9: Clear renaming.
Renaming ShPrintOptions to ShFormatOptions in the import statement appears consistent with its usage throughout the file.


13-13: Exporting languages is straightforward.
Re-exporting from ./languages.js is a clean approach.


15-17: Check test coverage for DockerfilePrintOptions usage.
This interface is fairly simple, but please consider adding tests to verify indent handling for Dockerfiles.


19-23: Extended parser options look good.
Adding filepath to ShParserOptions is logical for error tracking and fallback.


25-28: Confirmed new fields for ShPrintOptions.
Ensuring filepath and tabWidth are mandatory is appropriate.


48-87: Implementation of hasPragma is correct.
This function effectively detects @prettier or @format in leading comments. Consider adding tests with various top-of-file scenarios to improve coverage.


89-95: Consider test coverage for the dockerfileParser fallback.
Your parser simply returns its input. Tests ensuring Dockerfile parsing logic or fallback usage are currently missing (lines 93-94).

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 93-94: packages/sh/src/index.ts#L93-L94
Added lines #L93 - L94 were not covered by tests


97-116: Add coverage for empty Dockerfile scenario.
The check for a non-existent node (line 109) is untested, which can happen if the file is empty. Consider a test that verifies we return an empty string.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 109-109: packages/sh/src/index.ts#L109
Added line #L109 was not covered by tests


120-151: Fallback to Dockerfile parse upon shell parse error.
This is a valid approach but confirm users truly intend a Dockerfile fallback for all parse failures. Tests for the fallback scenario might help confirm correctness.


153-218: Enhance test coverage for empty node and throw flow.
Lines 183 (returning '' if no node) and 216 (throwing the original error) are missed by tests. Consider adding a test to trigger each path.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 183-183: packages/sh/src/index.ts#L183
Added line #L183 was not covered by tests


[warning] 216-216: packages/sh/src/index.ts#L216
Added line #L216 was not covered by tests


221-224: Exported parsers are clearly separated.
Exporting dockerfileParser and shParser distinctly makes usage more explicit.


226-229: Exported printers are clearly separated.
Defining separate printers for Dockerfile vs. shell content seems consistent.


231-398: Options object is comprehensive.
The structured export of shell formatting options is clear. No immediate issues noted.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
.size-limit.json (1)

11-13: Updated Size Limit for Dockerfile Parser Module

The new size limit of "3.4kB" for packages/sh/lib/index.js appears to be a deliberate adjustment to accommodate the added functionality (e.g., integration of @reteps/dockerfmt as a fallback formatter) and any associated code size increase. Please verify that this revised limit meets your bundle size constraints and performance goals.

packages/sh/README.md (2)

20-23: Clarify the Dockerfile fallback explanation

The updated section clearly explains that Dockerfile support now benefits from dockerfmt as a fallback when sh-syntax fails. Consider explicitly emphasizing that this fallback behavior only occurs on parsing failure, which might help users understand when dockerfmt is employed.


38-39: Minor language suggestion for clarity

The phrase “We can not do much on our side” would read better as “We cannot do much on our side.” This minor edit improves clarity and aligns with common style conventions suggested by static analysis.

Consider applying this diff:

-    We can not do much on our side. See also <https://github.com/un-ts/prettier/issues/336>.
+    We cannot do much on our side. See also <https://github.com/un-ts/prettier/issues/336>.
🧰 Tools
🪛 LanguageTool

[style] ~39-~39: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...cases can be handled correctly. > We can not do much on our side. See also <https://...

(CAN_NOT_PREMIUM)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 610865b and a16e14f.

📒 Files selected for processing (3)
  • .changeset/tiny-ghosts-press.md (1 hunks)
  • .size-limit.json (1 hunks)
  • packages/sh/README.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/tiny-ghosts-press.md
🧰 Additional context used
🪛 LanguageTool
packages/sh/README.md

[style] ~39-~39: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...cases can be handled correctly. > We can not do much on our side. See also <https://...

(CAN_NOT_PREMIUM)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (1)
packages/sh/README.md (1)

25-36: JSON usage example is clear and complete

The sample JSON configuration for enabling the Dockerfile parser is well formatted and helpful. It provides a practical example for users configuring their .prettierrc file. No changes are needed here.

Copy link

sonarqubecloud bot commented Apr 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant