0.0.0 • Published 5 months ago

eslint-formatting-reporter v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

eslint-formatting-reporter

npm version npm downloads bundle JSDocs License

Report differences between the formatted and unformatted code for ESLint. Useful to create ESLint plugins that format plain code.

A thin wrapper around prettier-linter-helpers, extracted from eslint-plugin-prettier.

Usage

import { messages, reportDifferences } from 'eslint-formatting-reporter'
import type { Rule } from 'eslint'

// New ESLint Rule
export default <Rule.RuleModule>{
  meta: {
    type: 'layout',
    fixable: 'whitespace',
    messages
  },
  create(context) {
    return {
      Program() {
        const source = context.source.text
        const formatted = myFormat(source)

        reportDifferences(context, source, formatted)
      }
    }
  }
}

Sponsors

License

MIT License © 2023-PRESENT Anthony Fu