8000 feat: make `dockerfile` default, no fallback needed by JounQin · Pull Request #436 · un-ts/prettier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: make dockerfile 8000 default, no fallback needed #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025
Merged

Conversation

JounQin
Copy link
Member
@JounQin JounQin commented Apr 9, 2025

Summary by CodeRabbit

  • New Features
    • Dockerfile formatting is now enabled by default, simplifying configuration.
    • Expanded language support now treats Dockerfile files distinctly.
  • Documentation
    • Updated plugin details and warnings to clearly describe supported file types.
  • Chores
    • Upgraded dependency versions for smoother integration.
    • Corrected script headers to ensure proper shell script execution.
    • Introduced new tests to validate parser location functions for shell scripts.
    • Removed outdated test cases and streamlined existing tests for clarity.

@JounQin JounQin requested a review from Copilot April 9, 2025 01:35
Copy link
changeset-bot bot commented Apr 9, 2025

🦋 Changeset detected

Latest commit: c00ad78

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 Patch

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 9, 2025

Walkthrough

This pull request introduces a new changeset for the prettier-plugin-sh package that sets the dockerfile as the default option, removing the fallback mechanism. The README has been updated to clarify the plugin’s capabilities and warnings. The dependency @reteps/dockerfmt is bumped from ^0.2.5 to ^0.2.6. Code in src/index.ts has been streamlined by updating type signatures and removing error recovery logic. Additionally, test cases have been adjusted—with the shell script formatting test removed, Dockerfile test conditions simplified, and a shebang correction applied—and language support in languages.ts is expanded.

Changes

Files Change Summary
.changeset/eight-apricots-give.md, packages/sh/README.md Added changeset file documenting the dockerfile default update and updated documentation to better describe plugin capabilities and warnings.
packages/sh/package.json Updated dependency: @reteps/dockerfmt bumped from ^0.2.5 to ^0.2.6.
packages/sh/src/index.ts Modified parser logic: type signature revised, error handling and the errorCache removed, and simplified processing of Node types.
packages/sh/test/fixtures.spec.ts, packages/sh/test/fixtures/no-ext Removed shell script formatting test; updated Dockerfile test by eliminating filename conditions and parser specification; corrected the shebang line.
scripts/languages.ts Expanded getSupportedLanguages to accept dockerfile as a valid parser and adjusted the aceModes for the sh package.
packages/sh/test/error.spec.ts, packages/sh/test/loc-functions.spec.ts Modified test cases to remove parser specifications and added new tests for location functions of shell scripts.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as Prettier CLI
    participant Plugin as prettier-plugin-sh
    participant Lang as getSupportedLanguages
    participant Parser as shParser
    participant Printer as shPrinter

    U->>CLI: Submit file for formatting
    CLI->>Plugin: Delegate formatting task
    Plugin->>Lang: Request supported languages (parser='dockerfile')
    Lang-->>Plugin: Return language details
    Plugin->>Parser: Parse file content as Node
    Parser-->>Plugin: Return parsed Node
    Plugin->>Printer: Format parsed Node
    Printer-->>Plugin: Return formatted code
    Plugin-->>CLI: Deliver formatted output
    CLI-->>U: Output formatted file
Loading

Possibly related PRs

  • chore: release package(s) #431 – The changes in the main PR, which introduce a default dockerfile option in the prettier-plugin-sh package, are related to the retrieved PR that discusses the use of dockerfmt as a fallback printer and the introduction of dockerfile as a parser option.
  • chore: release package(s) #435 – The changes in the main PR are related to the updates in the packages/sh/package.json file regarding the @reteps/dockerfmt dependency, as both PRs involve version updates for this package, although they differ in the specific version numbers.
  • feat: prototype to use dockerfmt as fallback formatter #432 – The changes in the main PR, which set the dockerfile as the default option in the "prettier-plugin-sh" patch, are related to the retrieved PR that introduces dockerfmt as a fallback formatter specifically for Dockerfile parsing.

Poem

I'm a rabbit in a digital burrow,
Hopping through code with a cheerful glow.
Dockerfile now leads the dance,
With error checks removed by chance.
I nibble on bumps and changes so neat—
A techy carrot treat, oh what a tweet! 🐰🎉

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/loc-functions.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 a1a375b and c00ad78.

📒 Files selected for processing (1)
  • packages/sh/test/loc-functions.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/sh/test/loc-functions.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest

🪧 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 8000 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
@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 5 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • packages/sh/package.json: Language not supported
  • packages/sh/test/snapshots/fixtures.spec.ts.snap: Language not supported
  • packages/sh/test/fixtures/no-ext: Language not supported

Copy link
socket-security bot commented Apr 9, 2025

Updated and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@eslint-react/ast@1.40.41.42.1 None 0 93.1 kB rel1cx
npm/@eslint-react/core@1.40.41.42.1 None 0 155 kB rel1cx
npm/@eslint-react/eff@1.40.41.42.1 None 0 47.1 kB rel1cx
npm/@eslint-react/eslint-plugin@1.40.41.42.1 None 0 823 kB rel1cx
npm/@eslint-react/jsx@1.40.41.42.1 None 0 32 kB rel1cx
npm/@eslint-react/kit@1.40.41.42.1 None 0 26.8 kB rel1cx
npm/@eslint-react/shared@1.40.41.42.1 None 0 178 kB rel1cx
npm/@eslint-react/var@1.40.41.42.1 None 0 32.3 kB rel1cx
npm/@typescript-eslint/eslint-plugin@8.29.08.29.1 None +1 459 kB
npm/@typescri 8000 pt-eslint/parser@8.29.08.29.1 None +1 171 kB
npm/@typescript-eslint/type-utils@8.29.08.29.1 None 0 0 B
npm/@typescript-eslint/typescript-estree@8.29.08.29.1 None +1 96.7 kB
npm/@typescript-eslint/visitor-keys@8.29.08.29.1 None 0 14.2 kB jameshenry
npm/@vitest/eslint-plugin@1.1.391.1.40 None 0 284 kB veritemm
npm/electron-to-chromium@1.5.1321.5.134 None 0 0 B
npm/eslint-plugin-react-debug@1.40.41.42.1 None 0 28.6 kB rel1cx
npm/eslint-plugin-react-dom@1.40.41.42.1 None 0 132 kB rel1cx
npm/eslint-plugin-react-hooks-extra@1.40.41.42.1 None 0 66.2 kB rel1cx
npm/eslint-plugin-react-naming-convention@1.40.41.42.1 None 0 42.1 kB rel1cx
npm/eslint-plugin-react-web-api@1.40.41.42.1 None 0 59.2 kB rel1cx
npm/eslint-plugin-react-x@1.40.41.42.1 environment 0 333 kB rel1cx
npm/index-to-position@1.0.01.1.0 None 0 4.04 kB sindresorhus
npm/typescript-eslint@8.29.08.29.1 None 0 81.6 kB jameshenry

🚮 Removed packages: npm/is-date-object@1.1.0

View full report↗︎

Copy link
codesandbox-ci bot commented Apr 9, 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
pkg-pr-new bot commented Apr 9, 2025

Open in StackBlitz

prettier-plugin-autocorrect

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

prettier-plugin-pkg

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

prettier-plugin-sql

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

prettier-plugin-sh

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

prettier-plugin-toml

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

commit: c00ad78

Copy link
Contributor
github-actions bot commented Apr 9, 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.14 KB (-5.31% 🔽)
packages/sql/lib/index.js 2.4 KB (0%)

Copy link
codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.18%. Comparing base (78e090c) to head (c00ad78).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
+ Coverage   84.42%   86.18%   +1.76%     
==========================================
  Files          10       10              
  Lines         199      181      -18     
  Branches       52       46       -6     
==========================================
- Hits          168      156      -12     
+ Misses         30       24       -6     
  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
Contributor
github-actions bot commented Apr 9, 2025

📊 Package size report   -0.07%↓

File Before After
.changeset/eight-apricots-give.md 89 B
packages/sh/README.md 10.9 kB -4.7%↓10.4 kB
packages/sh/src/index.ts 13.0 kB -6.58%↓12.1 kB
packages/sh/test/__snapshots__/fixtures.spec.ts.snap 30.0 kB -5.08%↓28.5 kB
packages/sh/test/error.spec.ts 502 B -3.98%↓482 B
packages/sh/test/fixtures.spec.ts 1.5 kB -42.1%↓843 B
packages/sh/test/fixtures/no-ext 37 B 3%↑38 B
packages/sh/test/loc-functions.spec.ts 1.2 kB
scripts/languages.ts 2.9 kB 2%↑3.0 kB
Total (Includes all files) 3.1 MB -0.07%↓3.1 MB
Tarball size 1.1 MB -0.01%↓1.1 MB
Unchanged files
File Size
.changeset/config.json 313 B
.changeset/README.md 510 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 932 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 14.2 kB
packages/sh/index.d.cts 45 B
packages/sh/LICENSE 1.1 kB
packages/sh/package.json 1.5 kB
packages/sh/test/__snapshots__/shellscript.spec.ts.snap 394 B
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/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/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
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

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 (2)
packages/sh/README.md (1)

19-21: Simplified warning section.

The warning section has been streamlined to focus only on ignore files limitations now that dockerfile is the default option.

Consider using "cannot" instead of "can not" in line 21 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] ~21-~21: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...ge 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)

147-153: Error handling removed from parse method

The error handling logic has been removed from the parse method. The previous implementation likely had a try-catch block that would catch errors and provide a fallback mechanism.

This change aligns with making dockerfile the default parser with no fallback needed, but ensure the code properly propagates errors to callers instead of silently failing.

Consider adding some basic error handling or at least ensuring errors are properly propagated with clear messages:

 return processor(text, {
   filepath,
   keepComments,
   variant,
   stopAt,
   recoverErrors,
+  onError: (err) => {
+    throw new ShSyntaxParseError(err);
+  }
 })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 78e090c and e0a869b.

⛔ 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 (7)
  • .changeset/eight-apricots-give.md (1 hunks)
  • packages/sh/README.md (2 hunks)
  • packages/sh/package.json (1 hunks)
  • packages/sh/src/index.ts (3 hunks)
  • packages/sh/test/fixtures.spec.ts (1 hunks)
  • packages/sh/test/fixtures/no-ext (1 hunks)
  • scripts/languages.ts (2 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/sh/README.md

[style] ~11-~11: The phrase ‘a lot of’ might be wordy and overused. Consider using an alternative.
Context: ... account. This plugin adds support for a lot of files through [mvdan-sh][] via [sh-synt...

(A_LOT_OF)


[style] ~21-~21: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...ge 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] 133-134: packages/sh/src/index.ts#L133-L134
Added lines #L133 - L134 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (9)
.changeset/eight-apricots-give.md (1)

1-6: LGTM!

The changeset file correctly documents the feature change, making dockerfile the default option without needing fallback.

packages/sh/test/fixtures/no-ext (1)

1-1: Fixed shebang format.

Good correction of the shebang line from #/usr/bin/env sh to #!/usr/bin/env sh, which ensures proper shell script recognition by the operating system.

packages/sh/package.json (1)

53-53:

✅ Verification successful

LGTM! Dependency version updated.

The version bump of @reteps/dockerfmt from ^0.2.5 to ^0.2.6 aligns with making dockerfile the default parser option.


🏁 Script executed:

#!/bin/bash
# Verify if this is the latest stable version of the dependency

curl -s https://registry.npmjs.org/@reteps/dockerfmt | jq '.["dist-tags"].latest'

Length of output: 91


Dependency Update Verified

The update of @reteps/dockerfmt from ^0.2.5 to ^0.2.6 has been confirmed against the npm registry, which reports "0.2.6" as the latest stable version. This aligns with using dockerfile as the default parser option. LGTM!

packages/sh/README.md (1)

11-11: Improved clarity about supported file types.

The updated description more precisely indicates how the plugin supports various file types through the [sh-syntax] and [dockerfmt] libraries.

🧰 Tools
🪛 LanguageTool

[style] ~11-~11: The phrase ‘a lot of’ might be wordy and overused. Consider using an alternative.
Context: ... account. This plugin adds support for a lot of files through [mvdan-sh][] via [sh-synt...

(A_LOT_OF)

scripts/languages.ts (2)

39-41: Updated type signature to include 'dockerfile'.

Good addition of 'dockerfile' to the supported parser options in the type signature.


92-97: Made 'dockerfile' a first-class parser.

The code now correctly handles 'dockerfile' as a separate parser by:

  1. Including languages from getSupportedLanguages('dockerfile')
  2. Removing 'dockerfile' from the aceModes array for the 'sh' parser

This aligns with making 'dockerfile' the default option as stated in the changeset.

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

17-17:

✅ Verification successful

Test simplified to handle all fixtures without parser-specific conditions

The test case has been simplified to run formatting on all fixture files without conditionally specifying parsers based on file type (like checking if a file is named Dockerfile). This aligns with making dockerfile the default parser, but ensure the test suite still provides adequate coverage for both shell scripts and Dockerfiles.


🏁 Script executed:

#!/bin/bash
# Check if there are both shell script and Dockerfile fixtures in the test directory
fixtures_dir="packages/sh/test/fixtures"

echo "Checking test fixtures directory for different file types:"
ls -la "$fixtures_dir"

echo -e "\nCounting shell scripts and Dockerfiles:"
shell_count=$(find "$fixtures_dir" -name "*.sh" | wc -l)
dockerfile_count=$(find "$fixtures_dir" -name "Dockerfile*" | wc -l)

echo "Shell scripts: $shell_count"
echo "Dockerfiles: $dockerfile_count"

if [ "$shell_count" -eq 0 ] || [ "$dockerfile_count" -eq 0 ]; then
  echo "WARNING: Missing test fixtures for one of the supported file types"
fi

Length of output: 1716


Test Fixtures Coverage Verified

The updated test case now formats all fixture files uniformly without relying on parser-specific conditions. As confirmed by the verification script, the fixtures directory contains 5 shell scripts and 1 Dockerfile, ensuring that both file types remain well-covered after setting dockerfile as the default parser.

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

189-206: Simplified printer implementation

The printer implementation has been simplified to directly process the node as a File without checking for alternative types or using fallback mechanisms. This is consistent with the changes to the parser and aligns with making dockerfile the default.


130-135:

❓ Verification inconclusive

Simplified parser type signature and location functions

The parser type has been updated from Parser<Node | string> to Parser<Node>, and the location functions have been simplified to directly access Node properties without type checking for strings. This removes the string fallback handling, making the code cleaner but potentially less robust for edge cases.


🏁 Script executed:

#!/bin/bash
# Check test coverage for the modified location functions

echo "These location functions (lines 133-134) are not covered by tests according to codecov."
echo "Checking if there are any existing tests that exercise the parser location functions:"

rg -l "locStart|locEnd" packages/sh/test

Length of output: 408


Action required: Please manually verify the new location functions

The parser refactor now simplifies the type signature (from Parser<Node | string> to Parser<Node>) and accesses node locations directly via node.Pos.Offset and node.End.Offset, removing string fallback handling. However, based on the search in packages/sh/test, these location functions aren’t exercised by any tests, so their robustness in edge cases—especially those previously handled by string logic—remains unverified.

  • Verify: Manually test scenarios where nodes might previously have been strings.
  • Consider: Adding tests to cover the behavior of locStart and locEnd functions.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 133-134: packages/sh/src/index.ts#L133-L134
Added lines #L133 - L134 were not covered by tests

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: 1

🧹 Nitpick comments (2)
packages/sh/README.md (2)

11-11: Good enhancement to the plugin description.

The updated description clearly specifies the technology stack supporting the plugin, making it easier for users to understand its capabilities.

Consider being more specific than "a lot of files" for a more professional tone. Something like "various file formats" or "multiple file types" would be more precise.

🧰 Tools
🪛 LanguageTool

[style] ~11-~11: The phrase ‘a lot of’ might be wordy and overused. Consider using an alternative.
Context: ... account. This plugin adds support for a lot of files through [mvdan-sh][] via [sh-synt...

(A_LOT_OF)


20-21: Documentation streamlined with new default behavior.

The warning section has been appropriately simplified now that dockerfile is the default option. This aligns well with the PR's objective.

Minor grammar suggestion: "can not" should be "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] ~21-~21: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...ge 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 e0a869b and 0bfcefa.

⛔ 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 (8)
  • .changeset/eight-apricots-give.md (1 hunks)
  • packages/sh/README.md (2 hunks)
  • packages/sh/package.json (1 hunks)
  • packages/sh/src/index.ts (3 hunks)
  • packages/sh/test/error.spec.ts (0 hunks)
  • packages/sh/test/fixtures.spec.ts (1 hunks)
  • packages/sh/test/fixtures/no-ext (1 hunks)
  • scripts/languages.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/sh/test/error.spec.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • .changeset/eight-apricots-give.md
  • packages/sh/test/fixtures/no-ext
  • packages/sh/package.json
  • scripts/languages.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
packages/sh/src/index.ts

[warning] 133-134: packages/sh/src/index.ts#L133-L134
Added lines #L133 - L134 were not covered by tests

🪛 LanguageTool
packages/sh/README.md

[style] ~11-~11: The phrase ‘a lot of’ might be wordy and overused. Consider using an alternative.
Context: ... account. This plugin adds support for a lot of files through [mvdan-sh][] via [sh-synt...

(A_LOT_OF)


[style] ~21-~21: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ...ge 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 (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on 6D47 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 (4)
packages/sh/test/fixtures.spec.ts (1)

17-17: Test simplification aligns with making dockerfile the default.

The test case has been generalized to handle all fixtures without special conditions, which properly reflects the change to make dockerfile the default parser without fallbacks.

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

130-130: Type signature properly narrowed.

The type signature has been updated from Parser<Node | string> to Parser<Node>, which is more precise and removes the string fallback, aligning with the PR's objective to make dockerfile the default without fallbacks.


147-154: Error recovery logic removed.

The error handling and fallback to the original text has been removed, which is consistent with making dockerfile the default option. This simplifies the code but means errors will now propagate directly to the caller.


189-206: Streamlined processing in shPrinter.

The conditional check for node type has been removed, and the function now directly processes the node as a File. This simplification is appropriate given the type narrowing earlier in the code.

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 (4)
packages/sh/test/loc-functions.spec.ts (4)

9-22: Well-structured test with clear assertions.

This test appropriately verifies the basic functionality of the location functions with a simple shell script. The comments before each assertion improve readability.

However, consider adding more specific tests for the shebang line itself, to ensure it's properly parsed.

+ it('should correctly handle shebang line', async () => {
+   const script = '#!/bin/sh\necho "test"'
+   const node = await parsers.sh.parse(script, {
+     filepath: 'test.sh',
+     locStart,
+     locEnd,
+   } as ParserOptions<Node>)
+   
+   // Check that we can access the first command (echo)
+   const command = node.commands?.[0]
+   expect(command).toBeDefined()
+   // The command should start after the shebang line
+   expect(locStart(command)).toBeGreaterThan(8)
+ })

24-47: Good coverage of different shell script constructs.

This test effectively verifies that location functions work with various shell syntax constructs.

Consider two improvements:

  1. Add more complex shell script constructs (nested structures, loops, command substitutions)
  2. Split into individual test cases for better failure isolation
- it('should handle scripts with various syntax constructs', async () => {
-   const scripts = [
-     // Simple command
-     'echo "simple"',
-
-     // If statement
-     'if [ "$1" = "test" ]; then\n  echo "test"\nfi',
-
-     // Function definition
-     'function say_hello() {\n  echo "Hello"\n}',
-   ]
-
-   for (const script of scripts) {
-     const node = await parsers.sh.parse(script, {
-       filepath: 'test.sh',
-       locStart,
-       locEnd,
-     } as ParserOptions<Node>)
-
-     expect(locStart(node)).toBe(0)
-     expect(locEnd(node)).toBe(script.length)
-   }
- })
+ it('should handle simple commands', async () => {
+   const script = 'echo "simple"'
+   const node = await parsers.sh.parse(script, {
+     filepath: 'test.sh',
+     locStart,
+     locEnd,
+   } as ParserOptions<Node>)
+   
+   expect(locStart(node)).toBe(0)
+   expect(locEnd(node)).toBe(script.length)
+ })
+
+ it('should handle if statements', async () => {
+   const script = 'if [ "$1" = "test" ]; then\n  echo "test"\nfi'
+   const node = await parsers.sh.parse(script, {
+     filepath: 'test.sh',
+     locStart,
+     locEnd,
+   } as ParserOptions<Node>)
+   
+   expect(locStart(node)).toBe(0)
+   expect(locEnd(node)).toBe(script.length)
+ })
+
+ it('should handle function definitions', async () => {
+   const script = 'function say_hello() {\n  echo "Hello"\n}'
+   const node = await parsers.sh.parse(script, {
+     filepath: 'test.sh',
+     locStart,
+     locEnd,
+   } as ParserOptions<Node>)
+   
+   expect(locStart(node)).toBe(0)
+   expect(locEnd(node)).toBe(script.length)
+ })
+
+ it('should handle more complex constructs', async () => {
+   // Add test for a more complex example, e.g. with loops and nesting
+   const script = 'for i in $(seq 1 3); do\n  if [ "$i" -eq 2 ]; then\n    echo "Found $i"\n  fi\ndone'
+   const node = await parsers.sh.parse(script, {
+     filepath: 'test.sh',
+     locStart,
+     locEnd,
+   } as ParserOptions<Node>)
+   
+   expect(locStart(node)).toBe(0)
+   expect(locEnd(node)).toBe(script.length)
+ })

10-15: Consider extracting a helper function for parsing.

The call to parsers.sh.parse is duplicated across tests. Consider extracting a helper function to reduce duplication.

+ const parseScript = async (script: string) => {
+   return parsers.sh.parse(script, {
+     filepath: 'test.sh',
+     locStart,
+     locEnd,
+   } as ParserOptions<Node>)
+ }
+
  it('should return correct offsets for simple shell scripts', async () => {
    const script = '#!/bin/sh\necho "Hello, world!"'
-   const node = await parsers.sh.parse(script, {
-     filepath: 'test.sh',
-     locStart,
-     locEnd,
-   } as ParserOptions<Node>)
+   const node = await parseScript(script)

36-41: Tests only basic node positions.

The current tests only verify the root node's position. Consider testing specific node positions within the AST to ensure nested structures are correctly located.

 for (const script of scripts) {
   const node = await parsers.sh.parse(script, {
     filepath: 'test.sh',
     locStart,
     locEnd,
   } as ParserOptions<Node>)

   expect(locStart(node)).toBe(0)
   expect(locEnd(node)).toBe(script.length)
+  
+  // Test positions of child nodes when available
+  if (node.commands && node.commands.length > 0) {
+    const firstCommand = node.commands[0]
+    expect(locStart(firstCommand)).toBeGreaterThanOrEqual(0)
+    expect(locEnd(firstCommand)).toBeLessThanOrEqual(script.length)
+    expect(locEnd(firstCommand)).toBeGreaterThan(locStart(firstCommand))
+  }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0bfcefa and bb98cb9.

📒 Files selected for processing (2)
  • packages/sh/README.md (2 hunks)
  • packages/sh/test/loc-functions.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/sh/README.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/sh/test/loc-functions.spec.ts (1)
packages/sh/src/index.ts (1)
  • parsers (210-213)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (2)
packages/sh/test/loc-functions.spec.ts (2)

1-5: Good import organization.

The imports are well-structured, separating type imports from module imports with a blank line.


6-8: Clear test suite setup.

The test suite is well-organized, and extracting the location functions directly in the describe block makes them easily accessible for all tests.

Copy link
sonarqubecloud bot commented Apr 9, 2025

@JounQin JounQin merged commit 560ba3f into master Apr 9, 2025
36 checks passed
@JounQin JounQin deleted the feat/dockerfmt branch April 9, 2025 02:25
@JounQin JounQin mentioned this pull request Apr 9, 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
Development

Successfully merging this pull request may close these issues.

1 participant
0