feat: support non-js languages#743
Merged
JounQin merged 5 commits intoprettier:mainfrom Jun 17, 2025
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #312
This PR aims to support non-JS languages being linted with the
prettier/prettierruleCurrently, this plugin only runs on
Programnodes, which is typically the root node for languages that are processed into JS in ESLint. However, other eslint plugins may use a different root node type, such as@eslint/json'sDocumentnode typeThis PR expands support for other languages by making 2 changes:
Programnodes when instantiating the rule, the rule now matches the type of the root node that was parsed for the entire file.@eslint/js'sgetLocFromIndex, use a new local functiongetLocFromOffsetthat transforms a byte offset into an API-compatible location.The latter change was necessary because eg
@eslint/jsondoesn't include agetLocFromIndexmethod on itsSourceCodeclass.Important
This PR expands the
prettier/prettierESLint rule to support non-JS languages by matching the root node type and introducesgetLocFromOffsetto handle byte offsets.prettier/prettierrule to support non-JS languages by matching the root node type of the parsed file instead of onlyProgramnodes.getLocFromIndexwithgetLocFromOffsetto convert byte offsets to locations, supporting languages withoutgetLocFromIndex.getLocFromOffset()to calculate line and column from byte offset ineslint-plugin-prettier.js.reportDifference()to usegetLocFromOffset()instead ofgetLocFromIndex.[sourceCode.ast.type]instead ofProgramineslint-plugin-prettier.js.This description was created by
for ee09d11. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit