4.0.2 • Published 5 years ago

echint v4.0.2

Weekly downloads
1,003
License
ISC
Repository
github
Last release
5 years ago

ECHint

License version Build Status

Quick validation of files with EditorConfig.

Install

The easiest way to use ECHint to check your code is to install it globally as a Node command line program. To do so, simply run the following command in your terminal (flag -g installs echint globally on your system, omit it if you want to install in the current working directory):

npm install --only=production --save --global echint

After you've done that you should be able to use the echint CLI. The simplest use case would be checking all files in the current working directory:

$ echint
Error: some files did not pass EditorConfig validation:
  src/index.js:97 Expected a newline at the end of the file.
  src/path/data.json:2 Unexpected tabs found.

You can optionally pass one or more paths using the glob pattern:

$ echint *.js docs/**/*.md

How do I ignore files?

The path node_modules/** and hidden files/folders (beginning with .) are automatically excluded when looking for files to check.

Sometimes you need to ignore additional folders or specific minified files. To do that, add a echint.ignore property to package.json:

"echint": {
  "ignore": [
    "**/out/**",
    "**/build/**"
  ]
}

Can I use a sharable configuration?

Yes, you may prefer to check your code against a centralized .editorconfig. To do that, add a echint.extends property to package.json:

"echint": {
  "extends": "echint-config-some-config"
}

echint will use the main property or .editorconfig file from that package as the configuration. The echint-config- prefix will be added automatically if it is not already present.

use your ENV

echint uses dotenv to load the following environment config values:

nametypedescription
ECHINT_CONFIGstringpath to .editorconfig file
ECHINT_IGNOREstringpattern of files to ignore
ECHINT_PATTERNstringpattern of file to process
ECHINT_READ_PACKAGEstringread additional options from package.json ("true", "false")

you can create a local .env or .env.[NODE_ENV] file to modify echint's default behavior (where NODE_ENV is the name of your environment), or you can test this directly from the shell:

$ ECHINT_CONFIG=**/* echint *.js docs/**/*.md

include in your tests

  1. Add it to package.json

    {
      "name": "my-cool-package",
      "devDependencies": {
        "echint": "^1.0.0"
      },
      "scripts": {
        "test": "echint && node my-tests.js"
      }
    }
  2. Validate all files automatically when you run npm test

    $ npm test
    Error: some files did not pass EditorConfig validation:
      src/index.js:97 Expected a newline at the end of the file.
      src/path/data.json:2 Unexpected tabs found.
  3. Never deal with inconsistencies in a pull request again!

Usage

  Usage: echint [options] <file ...>

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -c, --config [path]  specify path for config file (defaults to ./.editorconfig)
    -i, --ignore [file]  files to ignore
    -p, --skip-package   whether to skip reading config info from package.json
    -q, --quiet          shhh
    -v, --verbose        detailed errors
Examples
# run with defaults
$ echint

# run on a subset of files
$ echint *.js *.md --verbose

# ignore some files
$ echint * --ignore *.md  --verbose

# use custom config file path
$ echint --config ~/.editorconfig  --verbose

API

echint()

validate everything in current directory

echint(files, [, options [, callback]]])

returns true | false

Parameters

nametypedescriptionrequireddefault
filesmixedmanually defined list of files to processno**/*
optionsmixedsee optionsno
callbackmixedsee callbacknoundefined

Options

nametypedescriptionrequireddefault
configstringpath to .editorconfig fileno**/*
ignorearrayarray of files & patterns to ignoreno['coverage/**', 'node_modules/**', 'bower_components/**', '**[.jpg,.png,.gif,.ico]
patternstringpattern of file to processno**/*
readPackagebooleanread additional options from package.jsonnotrue

Callback

pass a callback with the following signature:

function (errors, result) {
  /* typeof errors === 'object' */
  /* typeof result === 'boolean' */

  /*
    errors = {
      fileName: {
        lineNumber: [
          error details
        ]
      }
    }
  */
}
Examples
import echint from 'echint'

const files = [
  'path/to/file.js',
  'path/to/file.css'
]

const options = {
  config: 'path/to/.editorconfig'
}

function done (errors, valid) {
  if (!valid) {
    console.log(errors)
  }
}

// with defaults
echint()

// with file list
echint(files)

// with options
echint(options)

// with callback
echint(done)

// all together!
echint(files, done)
echint(files, options)
echint(files, options, done)
echint(options, done)

:copyright: ahmadnassri.com  ·  License: ISC  ·  Github: @ahmadnassri  ·  Twitter: @ahmadnassri

4.0.2

5 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.0

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.5.3

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago