Support `eslint native` non-JS languages for prettier
Clear and concise description of the problem
The format/prettier rule currently only supports JavaScript and TypeScript files unless providing a custom parser.
Current Limitation
The current implementation in src/rules/prettier.ts hardcodes the Program AST event:
return {
Program() {
// Formatting logic here
}
}
However, different languages use different AST root node types, e.g. JavaScript and TypeScript use Program, whereas the eslint/markdown plugin requires a root node type.
Use Cases
This limitation prevents me from formatting markdown files with prettier while also using eslint/markdown linting rules.
Suggested solution
Implement dynamic AST type detection using context.sourceCode.ast.type:
return {
[sourceCode.ast.type || 'Program'](node) {
// Universal formatting logic
}
}
Alternative
No response
Additional context
eslint-plugin-prettier added support for non-js languages here. This could be used as a basis.
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guide.
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
I didn't know that! Do you like to start a quick PR for it? Thanks!