standard / standard-engine

:fire_engine: The guts of `standard` modularized for reuse

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prettier support

theoludwig opened this issue · comments

What problem do you want to solve?

Making standard ecosystem easier to use!
As discussed in : standard/ts-standard#102, standard/standard#1356, standard/standard#811
There is already prettier-standard but it would be cool, if it could work out of the box for packages like standard, semistandard, standardx, ts-standard etc.

What do you think is the correct solution to this problem?

Warning: It is a breaking change because, packages made with standard-engine would need to provide a prettierConfig path and a prettier instance.

  • New options.js with prettierConfig
const eslint = require('eslint')
const prettier = require("prettier")
const path = require('path')
const pkg = require('./package.json')

module.exports = {
  // homepage, version and bugs pulled from package.json
  version: pkg.version,
  homepage: pkg.homepage,
  bugs: pkg.bugs.url,
  eslint: eslint, // pass any version of eslint >= 1.0.0
  prettier: prettier, // pass any version of prettier >= 2.0.0
  cmd: 'pocketlint', // should match the "bin" key in your package.json
  tagline: 'Live by your own standards!', // displayed in output --help
  eslintConfig: {
    configFile: path.join(__dirname, 'eslintrc.json')
  },
  prettierConfig: {
   configFile: path.join(__dirname, '.prettierrc.json')
  },
  cwd: '' // current working directory, passed to eslint
}
  • New CLI flag --format

  • New options for engine.lintFiles (format: boolean):

{
  // unique to lintText
  filename: '',         // path of file containing the text being linted

  // common to lintText and lintFiles
  cwd: '',              // current working directory (default: process.cwd())
  fix: false,           // automatically fix problems
  format: true,         // aggressively format code for consistency
  extensions: [],       // file extensions to lint (has sane defaults)
  globals: [],          // custom global variables to declare
  plugins: [],          // custom eslint plugins
  envs: [],             // custom eslint environment
  parser: '',           // custom js parser (e.g. babel-eslint)
  usePackageJson: true, // use options from nearest package.json?
  useGitIgnore: true    // use file ignore patterns from .gitignore?
}

If format: true, it means we use the prettier api to format the code and also once prettier formatting is done, we also lint the files, so basically, if format: true, then implicitly fix: true because if we format we also lint.

Are you willing to submit a pull request to implement this change?

Yes!