Skip to content
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

linter Plugin support for 2.0 #3547

Closed
tjbenton opened this issue Dec 21, 2017 · 5 comments
Closed

linter Plugin support for 2.0 #3547

tjbenton opened this issue Dec 21, 2017 · 5 comments
Labels
status:awaiting response Issues that require answers to questions from maintainers before action can be taken

Comments

@tjbenton
Copy link

Currently the prettier eco system is a little bit spread out and confusing to work with when you're trying to get it to work with other packages.

Each of the packages above have their own unique cli and options which is great if you love a completely different experience and like to read documentation on how to use it.

While the discussions are going on for v2.0 I would like to propose adding support for plugins. This way there is only 1 way to use the prettier cli, not multiple ways.

The other advantage of adding support for plugins is that they can work together. For example when parsing markdown files each of the js blocks and be parsed using eslint, or each of the scss blocks could be parsed with the stylelint plugin. That way not only are all the files formatted correctly according to eslint/stylelint/etc. they're also formatted correctly in markdown files. Another example would be with vue files and script, and style tags since you can specify the language that's used.

Here's a rough concept of what the plugin api could look like.

export default {
  // this defines the languages that this plugin supports. This is determined in 3 different ways
  // 1. By the file extension
  // 2. By the language attr/element
  //   - `<script>` This assumes the language is js
  //   - `<script lang="js">` same thing as above
  //   - `<style>` // assumes css
  //   - `<style lang="css">` same thing as above
  //   - `<style lang="scss">` changes language to css
  // 3. By the codeblock language
  // 
  //   - ```js
  //     const foo = ''
  //     ```
  //   - ```scss
  //     .foo { background: blue; }
  //     ```
  // They can pass in string/array/regex
  lang: [ 'js', 'jsx' ],
  // runs before the file is returned/written
  handler({ 
    // any options that are passed to prettier, this way if a 
    // plugin needs access to one of them they have it
    options,
    // the code that's going to formatted
    content,
  }) {
    // the modified content would be returned
    return content
  },
}
@j-f1
Copy link
Member

j-f1 commented Dec 21, 2017

FYI prettier-markdown has been superseded by markdown support included in Prettier by default.

@tjbenton
Copy link
Author

I know that but the prettier-markdown package hasn't been updated to say that it's deprecated, and direct people to use the built in markdown support.

@josephfrazier
Copy link
Collaborator

There's some work-in-progress on a plugin API at #3536

@azz
Copy link
Member

azz commented Dec 21, 2017

As @josephfrazier mentioned I'm working on a plugin API as we speak! See some notes: #3511 (comment) and #3511 (comment)

@alexander-akait
Copy link
Member

/cc @prettier/core i think we can close this issue

@alexander-akait alexander-akait added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Aug 7, 2019
@lipis lipis closed this as completed Aug 8, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:awaiting response Issues that require answers to questions from maintainers before action can be taken
Projects
None yet
Development

No branches or pull requests

6 participants