This skill is audited by AI and then modified file by file at specific points in the target project; it distributes only operational instructions, six configuration templates, and historical references. It must not create or invoke a migration CLI, runtime code, or bulk overwrite tools. First confirm configuration ownership and user changes, then perform the minimal modification.
Highest-Priority Contract
-
prettier-plugin-lint-mdMust precisely use1.0.1:package.jsonThe declared version, the lockfile-resolved version, and the runtime-resolved version must be consistent. Prohibit^1.0.1、~1.0.1or1.0.3。 -
Use a string at the top level of the single effective Prettier configuration:
plugins: ["prettier-plugin-lint-md"],Prohibit top-level object imports of lint-md, and prohibit registering only in a Markdown override. Do not use a single entry point partially passing to overturn these two contracts.
For the reasons and deprecated approaches, see references/version-matrix.md、references/runtime-loading-model.md and references/decision-evolution.md。
1. Confirm the operation root, configuration ownership, and user boundaries
- Locate the root from the current directory upward
package.json. For a pnpm monorepo, use the directory containingpnpm-workspace.yamlas the root; for an npm/yarn workspace, use the directory containing theworkspacesthat declarespackage.jsonas the root. - Read the root
package.json, the lockfile, and the five target configurations, and usegit status --short、git diff、git diff --cachedto check Git status. Existing changes belong to the user by default; do not overwrite, roll back, stage, or include unrelated modifications. - Scan and read one by one the root
package.jsonfield,prettier,prettier.config.*and.prettierrc*. If multiple active sources are found, the inheritance relationship is unclear, or a single effective configuration cannot be determined, stop and ask the user to decide; do not create a new dual configuration. - Before modifying, list the files that will be created or modified at specific points. Actions that modify package, lockfile,
git add --renormalize ., or the staging area, such as dependency installation, hook installation, and.git/hooks, must obtain the user's explicit authorization.
2. Six Templates
templates/.editorconfigtemplates/.gitattributestemplates/prettier.config.mjstemplates/lint-staged.config.mjstemplates/simple-git-hooks.mjstemplates/cloud-pr-prettier.yml(the GitHub PR cloud formatting workflow that must be installed)
When a target file is missing, the corresponding template may be copied; when it exists, it must be merged file by file at specific points, preserving project-specific rules and incident explanation comments, and the entire file must not be overwritten. In particular, the complete JSDoc above the top-level lint-md prettier.config.mjs in plugins is a protected knowledge block: it records version drift, the object approach, the override approach, and the corrections for the three entry points. It must not be deleted, compressed, moved to an irrelevant location, or changed into ordinary line comments; when adjustments are needed, first update the corresponding references/, then keep the JSDoc consistent with the current contract.
3. Precise dependencies and active commands
At the root devDependencies check prettier、@prettier/plugin-oxc、prettier-plugin-lint-md、lint-staged、simple-git-hooks. Only when the project already has a valid commitlint configuration, check and use @commitlint/cli; otherwise do not generate commit-msg。
Only after user authorization, use precise dependency installation commands:
pnpm add -Dw prettier @prettier/plugin-oxc prettier-plugin-lint-md@1.0.1 lint-staged simple-git-hooks
After installation, do not look only at dependency fields: read the lockfile, and resolve from the project execution root prettier-plugin-lint-md/package.json; all three places must be 1.0.1. The "package not found" issue under pnpm's strict isolation and the version entry point error are different problems; route them according to references/pnpm-resolution.md .
The ordinary CLI, the experimental CLI, and VSCode are three different loading entry points:
- Ordinary CLI: used for basic formatting and string plugin discovery.
- experimental CLI: the active command retains one and only one
--no-parallel。 - VSCode: use the workspace Prettier and the top-level
resolveConfig().plugins; after modifying dependencies or resolution rules, the extension window must be restarted.
package.json The experimental active command form is as follows; when prepare already exists, keep the original command and concatenate simple-git-hooks:
{
"scripts": {
"format": "prettier --experimental-cli --write --no-parallel .",
"prepare": "simple-git-hooks"
}
}
The default active command does not repeatedly pass in --plugin: A/B experiments prove that after the experimental CLI discovers the config upward from the root cwd, the top-level string can already automatically load lint-md. Explicit --plugin serves only as a diagnostic/isolation verification means for plugin resolution failures, not as a more robust production configuration. For command boundaries, see references/runtime-loading-model.md。
4. Per-file processing
Prettier
Preserve the existing project style and overrides, ensuring endOfLine: "lf". lint-md must be the only effective top-level string element of the configuration:
export default {
plugins: ["prettier-plugin-lint-md"],
endOfLine: "lf",
};
Only when the top-level plugins of the sole effective configuration is a locatable static array may AI migrate the exact object import or string within it into the aforementioned string element. During migration, handle only lint-md, preserving other literal plugins, the original order, and comments. For dynamic plugins, spread, computed keys, variable indirection, multiple configurations, or when the top-level configuration cannot be uniquely located, stop and ask the user to decide; do not use regex to guess the migration.
package.json#prettier、JSON/JSONC/YAML .prettierrc* or CJS configuration can likewise express a string plugin; if the sole effective configuration does not have a clear and safe pinpoint modification location, stop and ask the user to decide whether to migrate to prettier.config.mjs. Do not migrate the configuration to ESM just for an object import.
For JSON with comments, add parser: "jsonc" override only for the exact file list; it is forbidden to change all **/*.json to JSONC, and the incident explanation comments must not be deleted to bypass formatting issues.
LF three layers
.gitattributesglobal text rules converge to* text=auto eol=lf, preserving binary and path-specific rules..editorconfigthe[*]block converges toend_of_line = lf, preserving other blocks.prettier.config.mjsconverges toendOfLine: "lf"。
Changing only .gitattributes will not refresh the Git index.git add --renormalize . will modify the staging area; the impact must be shown and authorization obtained, and multiple branches must be handled separately. Do not conflate the CRLF issue with lint-md not being loaded as the same root cause.
lint-staged and Hooks
lint-staged.config.mjs uses prettier --experimental-cli --write --no-parallel。simple-git-hooks.mjs by default only configures pre-commit; only after confirming an existing valid commitlint configuration may commit-msgbe retained or added. When encountering Husky, lefthook, custom core.hooksPath , or other hook managers, stop and ask the user to decide; do not overwrite.
The optional post-commit incident comment in the template must be preserved; this command may overwrite unstaged changes to the same file and must not be enabled by default.
5. Verification
Do not run only prettier --check; it may still pass when the plugin is not loaded. Verify with a temporary directory or temporary sample, then clean up:
# 版本三层一致性:依赖声明、lockfile、运行时解析均为 1.0.1
pnpm exec prettier --write <Markdown 样例>
pnpm exec prettier --experimental-cli --no-parallel --write <Markdown 样例>
node --check lint-staged.config.mjs
git diff --check
git status --short
Both CLIs must prove that the same mixed Chinese-English and numeric Markdown sample actually undergoes lint-md rule transformation. VSCode acceptance must confirm that the extension uses the workspace Prettier,resolveConfig(真实文件路径).plugins contains a top-level string, and editor formatting of the same sample produces the same result. For the complete script, see references/verification-playbook.md。
pnpm exec lint-staged --debug is not a read-only check: it executes lint-staged tasks and may rewrite files, the staging area, and trigger the stash flow. Only after user authorization, run this command,pnpm exec simple-git-hooks, real commit verification, or git add --renormalize .; before and after execution, git status --short、git diff and git diff --cached。
6. GitHub PR cloud formatting (unconditional installation)
Copy templates/cloud-pr-prettier.yml unconditionally to the target project's .github/workflows/; do not treat this template as an optional installation item. In the security job for same-repository PRs, after the template checks out the PR head it must unconditionally run pnpm install --frozen-lockfile, and must not rely on setup-js 's auto-install or skip dependency installation via a condition; fork PRs still skip the write-back job according to the security boundary below. This workflow must satisfy the following boundaries:
- Use the
pull_requestevent (opened、synchronize、reopened、ready_for_review) and concurrency keyed by PR number; do not switch topull_request_targetin order to obtain write permissions, and do not execute code from a fork without checking repository ownership. - Commits and pushes are allowed only when
github.event.pull_request.head.repo.full_name == github.repository. Fork PRs may only run read-only checks, and untrusted code and write permissions must not be placed in the same job. - Do not reference the target repository's local composite actions or monorepo-specific initialization actions. Environment initialization follows sxzz
setup-js's portable order: checkout PR head →pnpm/action-setup→actions/setup-node(Node version, pnpm cache) →pnpm install. Use--frozen-lockfileby default; only when there is no lockfile or the project explicitly requires an exception may the project maintainer explicitly disable it. - The workflow should identify the Node/pnpm version from
package.json#packageManageror the repository's existing configuration; do not write a particular monorepo's private package names, filters, scripts, or action paths into the general template. Action versions should be pinned to reviewed versions (production repositories should prefer immutable SHAs and retain version comments). - Obtain only the formattable files between
base.sha...head, and invoke the project-localpnpm exec prettier --experimental-cli --no-parallel --writeon each one; do not format the entire repository, and do not add lockfiles, generated artifacts, or files the user did not modify to the commit. - After formatting, first run
git diff --cached --checkon the exact file list. If there are no changes, do not commit; if there are changes, commit using thegithub-actions[bot]identity and push only the PR head branch.permissionsAt minimum, explicitly declarecontents: write、pull-requests: read, and keep the job-level same-repository condition.
For the general template and security/portability notes, see references/pr-workflow.md。