royriojas / eslint-friendly-formatter

A simple formatter/reporter for ESLint that's friendly with Sublime Text and iterm2 "click to open file" functionality
MIT License
198 stars 28 forks source link

Create Executable #5

Closed IanVS closed 9 years ago

IanVS commented 9 years ago

The idea here is to create an executable which users can use just like the ESLint cli, except it they will be using eslint-friendly-formatter. The usage is:

eslint-friendly code-to-lint.js

...which will in fact launch:

eslint code-to-lint.js --formatter 'path/to/eslint-friendly-formatter/index.js'

Any other command line arguments passed to eslint-friendly will also be passed along to eslint.

This works as long as ESLint is installed globally or in the package being linted. It looks first for eslint in the node_modules of the package, and if one is not found, it will look in parent directories all the way up to global packages. If no eslint is found, an error is thrown.

royriojas commented 9 years ago

like eslinter? https://www.npmjs.com/package/eslinter

I guess by philosophy, the formatters should just be plain modules without the executables, I made the eslinter wrapper over eslint, mainly to have it configured with this formatter by default and to provide a cache option. For a codebase with thousands of files the cache does an excellent job on only operating over the files that have actually changed.

Check eslinter and let me know what do u think...

IanVS commented 9 years ago

Like it in what manner? This change seems significantly simpler than eslinter. The main benefit here is it would allow this package to be installed and executed globally if desired, with a simple syntax. The current method of use would also continue to function as well.

royriojas commented 9 years ago

as I say, you can install eslinter globally too

Usage: eslinter [options] glob [glob1] [glob2]..[globN]

Options:
  -f, --format String  the formatter to use to format the output of the tool. If none specified this
                       will use `eslint-friendly-formatter` - default: eslint-friendly-formatter
  -u, --useCache
      If true, this module will remember the `mtime` and `size` of the linted files that passed
      validation and only operate on the ones that changed. If false, the cache will be destroyed.
      Cache will only be kept between executions with the useCache flag set to true.
  -h, --help           Show this help
  -v, --version        Outputs the version number
  -q, --quiet          Show only the summary info
  -c, --config String
      Path to your `eslint` config, if not provided will try to use the `.eslintrc` file in your
      current working directory, if not found will use the one provided with this package. Check:
      http://eslint.org/docs/user-guide/configuring for more info about the configuration options.

For me it seems it is kinda overlapping functionality with eslinter.

I would prefer to keep this particular module without the executable, but I will consider adding it. Let me think about this.

Regards

IanVS commented 9 years ago

I haven't come across any clear guidance from the ESLint team on how custom formatters are intended to be used, other than that they are only available in the cli for now.

Ping @nzakas, do you have any thoughts on making a custom formatter spawn ESLint with the --format flag pre-set? Is there a better or easier way to use custom formatters?

nzakas commented 9 years ago

Custom formatters are designed to take in a result set and output text, and to be specified on the command line. Custom formatters are just as easy to use as built-in ones because they work exactly the same way. I don't foresee any changes coming in how these work.

IanVS commented 9 years ago

Got it. Probably best to set up an alias to run eslint globally with a custom formatter. Don't know why I didn't think of that at first.