Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-friendly-formatter

royriojas355.2kMIT4.0.1

simple formatter/reporter for eslint that's friendly with Sublime Text and iterm2 'click to open file' functionality

eslint, formatter, reporter, eslint formatter, stylish

readme

eslint-friendly-formatter

A simple formatter/reporter for ESLint that's friendly with Sublime Text and iterm2 "click to open file" functionality

NPM Version Build Status

Motivation for this module

I decided to use eslint to verify my code and sadly the reporter was not terminal friendly. Basically I cannot click on the file to open it with my text editor and go directly to the line where the error was reported. This module fixes that issue, by using the syntax that "sublime text" introduced to open files.

Filenames may be given a :line or :line:column suffix to open at a specific location.

This module is based on the original stylish formatter that is now part of ESLint, it adds the following

  • All the errors are reported at the end, so no more search for errors between tons of report lines
  • RuleIds are clickable on terminals like iTerm2 and take you to the ruleId documentation site.
  • A summary is shown at the end with the offended ruleIds, ruleIds are also clickable.
  • It also shows a bit of context where the error happened, Making easier to understand the nature of the error
  • If you use iTerm2 or Guake* the link for the file becomes clickable and will open your editor at the given line. Please make sure you have properly configured the option to open uris that matches files with your editor of choice. Sublime is a great choice!, but this should work as well with other editors that understand the pattern used by sublime

    * Note: Until Guake v0.7.3 is released, it may be necessary to compile master from source.

Example of the output

screenshot

install

npm i --save-dev eslint-friendly-formatter

Intellij/Webstorm/PhpStorm integration

  1. Install eslint and eslint-friendly-formatter.

    npm i -D eslint eslint-friendly-formatter
  2. Add a script to your package json like:

    {
      "scripts": {
        "eslint": "eslint --format 'node_modules/eslint-friendly-formatter' file1 file2 dir1/ dir2/",
      }
    }

    Note: In windows you might not need the quotes around the path to the module.

    {
      "scripts": {
        "eslint": "eslint --format node_modules/eslint-friendly-formatter file1 file2 dir1/ dir2/",
      }
    }

    see issue #17

  3. Create a external tool to run eslint using this module as your formatter like this

    • program: npm
    • parameters: run eslint
    • working directory: $ProjectFileDir$
  4. Use an output filter like:

    $FILE_PATH$.*:$LINE$.*:$COLUMN$
  5. When launching the tool now the files will be also clickable, see: screenshot

Usage

In the command line

# just make sure you pass the path to the module to the format option of eslint
eslint.js --format './node_modules/eslint-friendly-formatter/index.js' index.js test/ -c './eslint.json'

Or as a module

var eslint = require('eslint');
var opts = readJson('./path/to/options');

var engine = new eslint.CLIEngine( opts );
var report = engine.executeOnFiles( ['file1.js', 'file2.js'/*, ...*/] );
var results = report.results || [];

var formatter = require('eslint-friendly-formatter');
var output = formatter(results);

// this will print the report if any...
console.log(output);

It works with gulp and gulp-eslint

var friendlyFormatter = require("eslint-friendly-formatter");
// Your js task
gulp.task("javascript", function() {
  return gulp.src(["src/js/**/*.js"])
    // Your eslint pipe
    .pipe(eslint(".eslintrc"))
    .pipe(eslint.format(friendlyFormatter))
    // Continue your other tasks
    .pipe(concat("app.js"))
    .pipe(gulp.dest("dist/js"))
});

It should work well in with eslint-grunt or grunt-eslint

grunt.initConfig({
    // when using eslint-grunt:
    eslint: {
        options: {
            formatter: './node_modules/eslint-friendly-formatter'
        }),
        target1: {
            //..
        }
    },
    // when using grunt-eslint:
    eslint: {
        options: {
            format: './node_modules/eslint-friendly-formatter'
        }),
        target2: {
            //..
        }
    }
});

Formatter parameters

UPDATE:

We can pass variables to the formatter using a double dash at the end of the eslint command -- --eff-by-issue. So a new flag can be used to group eslint issues by ruleId instead as by file. This is useful if you want to fix at once all the errors/warnigs of the same kind.

Eslint does not support passing parameters to formatters from the cli yet.So in order to pass parameters to the formatter we will have to rely on environment variables

Command line options

--eff-filter

Only shows the errors/warnigs that match the given ruleId filter. This option will only filter the reported rules the error and warning counts will be the same as when all rules are reported same as the exit code.

eslint -f node_modules/eslint-friendly-formatter client/**/*.js server/**/*.js -- --eff-by-issue --eff-filter 'global-require' # notice the --

--eff-by-issue

Normally the reporter will group issues by file, which is handy for normal development. But there are some cases where you might want to fix all the errors of a same kind all at once. For those cases this flag can be used to make the reporter group the issues by ruleId.

eslint -f node_modules/eslint-friendly-formatter client/**/*.js server/**/*.js -- --eff-by-issue # notice the --

Important: don't forget to add the flag at the end and after -- otherwise it will be interpreted as a eslint parameter and will fail as that parameter is not known to eslint.

--eff-absolute-paths

Same as environment variable EFF_ABSOLUTE_PATHS. If set to true the paths will be absolute. Otherwise they will be relative to CWD.

ENV Variables

EFF_NO_GRAY

Disable the gray color output

We use the gray color to show some info about the context where the error/warning happens. If for some reason you want to disable the gray color, in cases like this one , you can do it using an environment variable.

export EFF_NO_GRAY=true

And the gray color won't be used.

EFF_ABSOLUTE_PATHS

Make the paths of the files in the reporter be absolute instead of relative as it is by default in the received results.

Some terminals work better with relative paths (like iTerm2 with fish) and other dislike it like Guake. So starting in version v.1.1.0 the paths will be relative by deafult. If you need the absolute please export the following variable

export EFF_ABSOLUTE_PATHS=true

EFF_EDITOR_SCHEME

If this parameter is set, a url will be output below the filename.

Some terminals only support clicking on urls, and editors can be configured to respond to custom url schemes.

export EFF_EDITOR_SCHEME=editor://open?file={file}&line={line}&column={column}

Changelog

License

MIT

changelog

eslint-friendly-formatter - Changelog

v4.0.1

  • Other changes

    • Allow for null message.source - e0fcea4, exbinary, 06/04/2018 14:03:56

      Addresses issue #29. Message source can be null when a Parsing error is encountered.

  • Documentation

v4.0.0

  • Other changes

  • Update tests snapshots after upgrading chalk. - 1951a8f, hsxfjames, 06/07/2017 20:56:30
  • Upgrade chalk to v2.0.1 && DO NOT use removed method chalk.stripColor - 25ff0b5, hsxfjames, 05/07/2017 04:35:34

v3.0.0

v2.0.7

v2.0.6

v2.0.5

  • Features

    • add --eff-filter option - cac606d, [Roy Riojas](https://github.com/Roy Riojas), 23/05/2016 01:30:10

      The --eff-filter filters the rules shown in the report. Usefule to filter only a given type of rule.

      Example

      The following will only show the warning for global-require ruleId

      eslint -f node_modules/eslint-friendly-formatter client/**/*.js server/**/*.js -- --eff-by-issue --eff-filter 'global-require' # notice the --
  • Documentation

v2.0.4

v2.0.3

  • Features

    • Add an option to group by issue - 39ef078, [Roy Riojas](https://github.com/Roy Riojas), 18/04/2016 14:07:15

      Eslint does not support passing arguments, but we can pass any parameters using -- --param-here. So now inside the reporter we can get the value like process.argv['--param-here']. This can be used to pass flags to the reporter so now we can do the following

      --eff-by-issue will group the report by issue type

      eslint -f 'node_modules/eslint-friendly-formatter' -- --eff-by-issue
  • Documentation

v2.0.2

v2.0.1

  • Refactoring

    • Add EFF_NO_LINK_RULES param. Fixes #18 - 7ed4647, [Roy Riojas](https://github.com/Roy Riojas), 10/04/2016 02:44:06

      • In your terminal run
      export EFF_NO_LINK_RULES=true # rules ids won't be linked to
      documentation

      Also as part of this commit, rules that contain /, a common pattern in eslint plugins, like react/jsx-quotes will generate a link to a google search for that rule.

  • Documentation

v2.0.0

v1.2.2

  • Features

v1.2.1

  • Build Scripts Changes
  • Fix error when message.source is undefined. - 7a3f6f7, [Nikola Kovacs](https://github.com/Nikola Kovacs), 18/08/2015 09:28:56

    This happens when the javascript file has a parsing error.

v1.2.0

  • Build Scripts Changes

v1.1.1

  • Build Scripts Changes
  • Enhancements

v1.1.0

  • Build Scripts Changes
  • Use npm run test instead of plain npm test - df4c642, royriojas, 17/05/2015 12:35:05
  • Documentation
  • Features

    • add environment option EFF_ABSOLUTE_PATHS. Fixes #7 - 271a749, royriojas, 14/07/2015 01:20:57

      export the env variable EFF_ABSOLUTE_PATHS to make the paths in the reporter be absolute. If the environment variable is not found the paths will be reported as eslint send them.

      EFF_ABSOLUTE_PATHS=true eslint -f
      path/to/eslint-friendly-formatter/index.js’ file1.js file2.js dir/

      Or

      add to your profile

      export EFF_ABSOLUTE_PATHS=true

      Ugly hack. But should work until this issue is resolved:

      https://github.com/eslint/eslint/issues/2989

  • Other changes

  • Add Guake - 4ff1321, [Ian VanSchooten](https://github.com/Ian VanSchooten), 25/06/2015 23:21:23

    Current master of Guake will also auto open a configured editor to the correct line number.

    • Cosmetic fixes
  • Add a space for better readability - 4bec078, royriojas, 17/05/2015 12:24:37

v1.0.8

  • Build Scripts Changes
  • Update prepush and changelogx dependency - fddbf5a, royriojas, 17/05/2015 11:50:01

v1.0.7

  • Build Scripts Changes
  • Fix for #3. eslint-friendly-formatter failing to install - bd77638, royriojas, 17/05/2015 11:44:17

Changelog

v1.0.6

  • Build Scripts Changes
  • Bug Fixes

    • Support for solarized theme, or other themes that use gray for the background. Fixes #2 - a8c3c71, royriojas, 16/05/2015 17:02:33

      Basically this fix removes the gray color if the environment variable EFF_NO_GRAY is set to the string true.

      this can be done very easily in bash doing:

      export EFF_NO_GRAY=true
  • Other changes

v1.0.5

  • Documentation
  • Enhancements
    • Use the full path to the file so IDEs like Webstorm or Intellij can parse the output - 4433a5e, [Roy Riojas](https://github.com/Roy Riojas), 18/03/2015 04:15:50

v1.0.4

  • Documentation