Git Product home page Git Product logo

eclint's Introduction

ECLint

Build Status npm version codecov npm license dependencies Status

npm

Introduction

ECLint is a tool for validating or fixing code that doesn't adhere to settings defined in .editorconfig. It also infers settings from existing code. See the EditorConfig Project for details about the .editorconfig file.

This version of ECLint runs on EditorConfig Core 0.15.x.

Installation

$ npm install [-g] eclint

Features

CLI

The command-line interface (CLI) for this project uses gitlike-cli to parse the eclint command, along with its check, fix and infer sub-commands. Internally, the command is sent to the API to do its magic.

Running eclint --help will provide the following help information:

$ eclint --help
Usage: eclint <command> [files...] [options]

Commands:
  check [files...]  Validate that file(s) adhere to .editorconfig settings
  fix   [files...]  Fix formatting errors that disobey .editorconfig settings
  infer [files...]  Infer .editorconfig settings from one or more files

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Check

The eclint check sub-command allows you to validate that files adhere to their respective EditorConfig settings. Running eclint check --help will provide you the following help information:

$ eclint check --help
eclint check [files...]

Options:
  --help                          Show help                                                             [boolean]
  --version                       Show version number                                                   [boolean]
  --indent_style, -i              Indentation Style                                                     [choices: "tab", "space", undefined]
  --indent_size, -s               Indentation Size (in single-spaced characters)                        [number]
  --tab_width, -t                 Width of a single tabstop character                                   [number]
  --end_of_line, -e               Line ending file format (Unix, DOS, Mac)                              [choices: "lf", "crlf", "cr", undefined]
  --charset, -c                   File character encoding                                               [choices: "latin1", "utf-8", "utf-8-bom", "utf-16le", "utf-16be", undefined]
  --trim_trailing_whitespace, -w  Denotes whether whitespace is allowed at the end of lines             [boolean]
  --insert_final_newline, -n      Denotes whether file should end with a newline                        [boolean]
  --max_line_length, -m           Forces hard line wrapping after the amount of characters specified    [number]
  --block_comment_start           Block comments start with                                             [string]
  --block_comment                 Lines in block comment start with                                     [string]
  --block_comment_end             Block comments end with                                               [string]

Running this sub-command without any [options] will use each file's EditorConfig settings as the validation settings. In fact, you don't even need to pass-in any CLI [options] for this sub-command to work, but doing so will allow you to override the .editorconfig file settings in cases where you want more fine-grain control over the outcome.

Each CLI option has both short and long flag variations. As such, you can use --indent_size 2 or -i 2, whichever you prefer. Short flags may be combined into a single argument. For example, -swe 2 lf is the same as -s 2 -w -e lf.

The [<files>...] args allows you to pass-in one or more file paths or globs. You may, however, need to surround your glob expressions in quotes for it to work properly. Unfortunately, in bash, you can't add a negative glob with "!foo.js". Instead, you can put square brackets around the ! and eclint will take care of it. For example, "[!]foo.js".

The result of running eclint check * in this project's root, if there were issues, would look something like the following:

Z:\Documents\GitHub\eclint\README.md: Invalid indent style: space

If any errors are reported, the Node process will exit with a status code of 1, failing any builds or continuous integrations you may have setup. This is to help you enforce EditorConfig settings on your project or team. For Travis-CI, you can do this by adding the following before_script block to your .travis.yml file:

before_script:
  - npm install -g eclint
  - eclint check * "lib/**/*.js"

This is the same method this project is doing in its own .travis.yml file for reference.

Now should be a great time to segue into the fix sub-command.

Fix

Warning, Stop! Warning! Fixing your files will change their contents. Ensure that your files are under version control and that you have committed your changes before attempting to fix any issues with them. You can also run the check command to know which files will change before you fix them.

The eclint fix sub-command allows you to fix files that don't adhere to their respective EditorConfig settings. Running eclint fix --help will provide you the following help information:

$ eclint fix --help
eclint fix   [files...]

Options:
  --help                          Show help                                                             [boolean]
  --version                       Show version number                                                   [boolean]
  --indent_style, -i              Indentation Style                                                     [choices: "tab", "space", undefined]
  --indent_size, -s               Indentation Size (in single-spaced characters)                        [number]
  --tab_width, -t                 Width of a single tabstop character                                   [number]
  --end_of_line, -e               Line ending file format (Unix, DOS, Mac)                              [choices: "lf", "crlf", "cr", undefined]
  --charset, -c                   File character encoding                                               [choices: "latin1", "utf-8", "utf-8-bom", "utf-16le", "utf-16be", undefined]
  --trim_trailing_whitespace, -w  Denotes whether whitespace is allowed at the end of lines             [boolean]
  --insert_final_newline, -n      Denotes whether file should end with a newline                        [boolean]
  --max_line_length, -m           Forces hard line wrapping after the amount of characters specified    [number]
  --block_comment_start           Block comments start with                                             [string]
  --block_comment                 Lines in block comment start with                                     [string]
  --block_comment_end             Block comments end with                                               [string]
  --dest, -d                      Destination folder to pipe source files                               [string]

You might notice this sub-command looks very similar to the check sub-command. It works essentially the same way; except, instead of validating files, it enforces the settings on each file by altering their contents. I'll let you read the check sub-command so I don't have to repeat myself.

One key difference you'll notice is an additional -d, --dest <folder> option. This option gives you control over where the result file tree will be written. Without this specified, the files will be overwritten in the source location by default.

Infer

The eclint infer sub-command allows you to infer what the EditorConfig settings should be for all files you specify. Running eclint infer --help will provide you the following help information:

$ eclint infer --help
eclint infer [files...]

Options:
  --help       Show help                                               [boolean]
  --version    Show version number                                     [boolean]
  --score, -s  Shows the tallied score for each setting                [boolean]
  --ini, -i    Exports file as ini file type                           [boolean]
  --root, -r   Adds root = true to your ini file, if any               [boolean]

This sub-command generates a report that reveals whatever trends you have growing in your project. That is, if it's more common to see 2-space indentation, the inferred setting would be indent_size = 2.

By default, the CLI will print out the report in JSON format.

$ eclint infer * "lib/**/*.js"

Outputs:

{
  "indent_style": "tab",
  "trim_trailing_whitespace": true,
  "end_of_line": "lf",
  "insert_final_newline": true,
  "max_line_length": 90
}

If this isn't enough information for you and you want the full report, complete with scores, you can add the -s, --score flag. Each setting will have a numeric value assigned to it that indicates the number of times that setting was inferred across the files:

$ eclint infer --score * "lib/**/*.js"

Outputs:

{
  "charset": {
    "": 1
  },
  "indent_style": {
    "undefined": 21,
    "tab": 13
  },
  "indent_size": {
    "0": 21,
    "tab":13
  },
  "trim_trailing_whitespace": {
    "true": 34
  },
  "end_of_line": {
    "lf": 34
  },
  "insert_final_newline": {
    "true": 1
  },
  "max_line_length": 86
}

You can pipe these files to any destination file you wish, like so:

$ eclint infer * "lib/**/*.js" > editorconfig.json

You can also use the -i, --ini flag to generate the report as an INI file format, which is exactly the format in which the .editorconfig file should be written. This means you can create your .editorconfig file automatically! Here's how you might do it:

$ eclint infer --ini * "lib/**/*.js" > .editorconfig

If this is your root .editorconfig file, you'll definitely want to pair the -i, --ini flag with the -r, --root flag to add root = true to your .editorconfig file. We'll combine the 2 short flags into one:

$ eclint infer -ir * "lib/**/*.js" > .editorconfig

Your root .editorconfig file should now read thus:

# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = tab
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
max_line_length = 90

Respect .gitignore

$ env eclint check $(git ls-files)

for compatible with Windows, you can install exec-extra

Locales currently supported:

  • en: English.
  • zh_CN: Simplified Chinese.
  • zh_TW: Traditional Chinese.

Rules

All EditorConfig rules are supported. Additionally, the max_line_length rule has been added to the set. This is not an official EditorConfig setting, so it's possible it may be removed in the future. For now, it's has a basic use in this tool.

charset

At this time, only the following encodings are supported:

  • latin1 (partial support)
  • utf-8
  • utf-8-bom (not actually an encoding, but it does have a BOM signature)
  • utf-16le
  • utf-16be

Unsupported encodings:

  • utf-32le
  • utf-32be
  • everything else

I'm working on getting a much broader set of supported encodings, but it's rather difficult to support, so it may take a while.

check

Reports the following errors:

  • invalid charset: <detected>, expected: <charset>
  • expected charset: <charset>
  • line <n>, column: <n>: character out of latin1 range: <character>
fix

Fixes supported charsets by adding or removing BOM signatures and encoding the text in the new charset.

infer

Only infers documents with BOM signatures. No other assumptions made at this time.

indent_style

Supported settings:

  • space
  • tab
check

A maximum of one error will be reported per line. The following errors will be reported, listed in order of priority:

  • line <n>: invalid indentation: found a leading <space/tab>, expected: <indent_style>
    • Reported when the very first character in the line is the opposing indent style.
  • line <n>: invalid indentation: found <n> <soft/hard> <tab/tabs>
    • This happens when the first character in the line is correct, but the wrong indentation is found somewhere else in the leading indentation.
  • line <n>: invalid indentation: found mixed tabs with spaces
    • Reported when a space is followed by a tab anywhere in the leading whitespace.
fix

The fix method can fix indentation in the following ways:

  • Replaces hard tabs with soft tabs or vice versa.
    • Alignment is preserved.
    • Mixed hard/soft tabs are fixed only if soft tabs match the indent_size or tab_width.
infer

Looks at the first character of each line to determine the strongest trend in your file.

indent_size

Supported settings:

  • An integer
  • tab (pulls value from tab_width)
check

Reports the following errors:

  • line <n>: invalid indent size: <n>, expected: <indent_size>
    • Reported when the inferred setting for the line is divided by the configuration setting with no remainder. See the infer method for more information.
fix

Fixing indent size issues without any knowledge of the written language or syntax tree is literally impossible. Any attempt would be completely unreliable. I welcome debate over this topic, but I've been over it again and again and it just can't be done. As such, each line is simply passed through without modification.

infer

If the first character in a line is a tab, the indent size will be undefined. If it's spaces, however, I count backwards from 8 to 1, dividing the number of leading spaces by this number. If there is no remainder, that number is inferred as the indent size. Every line is tallied up with a score for each possible indent size and the highest score wins for the document. I've found this method to be extremely reliable.

tab_width

Supported settings:

  • An integer

This tool only uses tab_width as a fallback for indent_size.

trim_trailing_whitespace

Supported settings:

  • true
check

Reports the following errors:

  • line <n>: unexpected trailing whitespace
fix

When true, removes trailing whitespace. Anything other than true is ignored.

infer

Infers true if no trailing whitespace is found. Infers undefined otherwise. Does not infer false under any scenarios.

end_of_line

Supported settings:

  • lf
  • cr
  • crlf
check

Reports the following errors:

  • line <n>: invalid newline: <detected>, expected: <end_of_line>
fix

Replaces all invalid newlines with the one defined in your configuration.

infer

Infers the most popular newline found in each document.

insert_final_newline

Supported settings:

  • true
  • false
check

Reports the following errors:

  • <expected/unexpected> final newline character
fix
  • When true, inserts a single newline at the end of the file.
  • When false, removes all newlines found at the end of the file.
infer
  • Infers true when no newlines are found at the end of the file.
  • Infers false when a newline is found at the end of the file.

max_line_length (unofficial)

Supported settings:

  • An integer
check

Reports the following errors:

  • line <n>: line length: <detected>, exceeds: <max_line_length>
fix

Unsupported.

infer

Scans an entire document for line length and infers the greatest line length detected, rounded up to the nearest 10 (e.g., 72 becomes 80).

block_comment_start

Defines the start of block comments

block_comment

Defines the start of line in block comments

block_comment_end

Defines the end of block comments

Support for doc comments

When you use doc comments, eclint might report a error with your indentation style. At this case, you need to defines the style of the doc comments you are using in .editorconfig:

[*]
# C-style doc comments
block_comment_start = /*
block_comment = *
block_comment_end = */

API

This project's API is written in TypeScript, a typed superset of JavaScript that compiles to plain JavaScript. Because it's written in TypeScript, the definition files come for free and are always in sync with the generated JavaScript.

If you have an IDE that supports TypeScript, this saves you time by letting you stay in your editor instead of constantly looking up documentation online to figure out the arguments, types and interfaces you can pass-in to API functions.

import * as eclint from 'eclint';

In JavaScript, you just need to require the package:

var eclint = require('eclint');

Now, you can pipe streams to the respective check, fix and infer sub-commands. Refer to cli.ts for a working example of doing just that.

Gulp Plugin

The check, fix and infer API commands are all Gulp plugins. Here's an example of how you might use them:

var gulp = require('gulp');
var eclint = require('eclint');
var reporter = require('gulp-reporter');
var path = require('path');

gulp.task('check', function() {
  return gulp.src([
      '*',
      'lib/**/*.js'
    ])
    .pipe(eclint.check())
    .pipe(reporter());
});

gulp.task('fix', function() {
  return gulp.src([
      '*',
      'lib/**/*.js'
    ],
    {
      base: './'
    })
    .pipe(eclint.fix())
    .pipe(gulp.dest('.'));
});

gulp.task('infer', function() {
  return gulp.src([
      '*',
      'lib/**/*.js'
    ])
    .pipe(eclint.infer({
      ini: true,
      root: true
    }))
    .pipe(gulp.dest('.editorconfig'));
});

Have a look at this project's check and fix tasks for a working example. Notice that the check tasks exits with an exit code of 1. This is to fail whatever continuous integration you may have in place.

Related Projects

eclint's People

Contributors

bitdeli-chef avatar bufferoverflow avatar denis-sokolov avatar fpuga avatar gucong3000 avatar jedmao avatar jednano avatar nicothin avatar silverwind avatar treyhunner avatar xuhdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eclint's Issues

Fix the indent spaces

Hi!

I saw that you think this tool doesn't suposse to fix indent spaces, but that's all why I downloaded it in the first place. I also try editorconfig-tools but it does not support wildcards out the box (I'm on Windows).

editorconfig-tools says that I can fix the indent spaces. Why this cannot? The .editorcofig file it's all about common configuration. Even if there is something wrong with the fix, there is nothing you can do, they just got the configuration wrong themselfs. I think that at least.

Thanks you!

Error in comment

In javascript (and many others), this is a common way to declare some documentation for a certain piece of code:

/**
 * Comment
 */

This exemple uses one space indentation, so if you set into your .editorconfig
indent_size = 2
and then you run eclint check on that exemple, it will give you this error:
invalid indent size: 1, expected: 2

I think it should be a way to ignore comments

fail to recognize utf-8-bom

echo test > test
eclint fix -c utf-8-bom test
eclint check -c utf-8-bom test

output:

test: expected charset: utf-8-bom

It seems eclint fix add bom successfully, but eclint check fail to recognize it... 😨

Please support files that just have extensions

Please support files that just have extensions

> eclint fix **/*
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, open 'MyApplication\.vs\MyApplication\v14\.suo'
    at Error (native)

Output verbosity

The current output seems hard to parse visually for me:

All I care about is filename, line number, column and a short and descriptive error. eslint is a good example:

screen shot 2017-07-30 at 10 48 20

Maybe it'd be good to have the minimal output without an argument and introduce --verbose for the current output.

Install fails

While running sudo npm install -g

npm ERR! Error: ENOENT, chmod '/usr/local/lib/node_modules/eclint/eclint.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.8.0-30-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "-g" "install" "."
npm ERR! cwd /home/trey/repos/node/eclint
npm ERR! node -v v0.10.17
npm ERR! npm -v 1.3.8
npm ERR! path /usr/local/lib/node_modules/eclint/eclint.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/trey/repos/node/eclint/npm-debug.log
npm ERR! not ok code 0

gulp build does not work for me

building eclint stops with error

[16:39:21] Starting 'scripts'...
node_modules/linez/linez.d.ts(2,25): error TS2307: Cannot find module 'd.ts/linez'.

steps before:

git clone ...
cd eclint
npm install

I'm doing anything wrong or forget something?

FYI: I'll need to locally modify eclint to handle block-comments correctly for me ... (these with leading space in front of "*" at 2nd line):

/**
 * description
 */

give error on check with settings

indent_style = tab
tab_width = 4

in .editorconfig

many thanks in advance

Consider suggesting alternative tools in the description

In light of your recent comment and resistance to add features, perhaps you would consider mentioning an alternative package in your descriptions so people could find them easier if they choose to?

I have chosen to move on to lintspaces, which seems to be pretty popular, supports .editorconfig files and ignore option I needed.

That’s not to say your package was not awesome, thanks for it!

fix does not fully fix all issues

I'm applying eclint to this file here: https://github.com/eisber/vowpal_wabbit/blob/master/vowpalwabbit/gd.cc.

'check' showed some issues and 'fix' fixed some of them. Running 'check' again still shows there are more issues, but now 'fix' doesn't do anything to the file. Any ideas? The editorconfig file being used is here: https://github.com/eisber/vowpal_wabbit/blob/master/.editorconfig

I'm on Ubuntu 14.04, npm 1.4.28, node v0.10.40, installed eclint by 'sudo npm install -g eclint'

1.1.3 is an empty release

PRs #32 and #33 only modify the source.
I did not notice that the project has build artifacts in the repository.
Please consider #33 and then rebuild to ensure that the JavaScript version is updated.

Consider not keeping build artifacts in the repository. Although not universally accepted, I'd say it's a generally accepted practice.

Sorry for the inconvenience.

Break valid block comment.

// #if _DEBUG
const apiServers = {
  rd: 'http://sharechargapi.jmstatic.com/index.php',
  pub: 'http://api-pub.ankerjiedian.com/index.php',
  prod: 'https://api.ankerjiedian.com/index.php'
};
/* #else
const apiServers = {
  prod: 'https://api.ankerjiedian.com/index.php'
};
// #endif */
src/config/index.js
    14:01 ❌️ invalid indent size: 0, expected: 3   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    15:01 ❌️ invalid indent size: 2, expected: 3   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    16:01 ❌️ invalid indent size: 0, expected: 3   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    17:01 ❌️ invalid indent size: 0, expected: 3   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    24:01 ❌️ invalid indent size: 0, expected: 3   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    25:01 ❌️ invalid indent size: 0, expected: 3   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    42:01 ❌️ invalid indent size: 2, expected: 5   (EditorConfig indent_size http://t.cn/Ro8MlrH)
    43:01 ❌️ invalid indent size: 2, expected: 5   (EditorConfig indent_size http://t.cn/Ro8MlrH)

Publish on NPM

As a Node.js newbie, I want eclint published on NPM, so that it's easy to install with npm [-g] eclint.

Correct indent_size setting to allow documentation comments

What is the correct setting to allow C-style block comments with documentation?

/**
 * ...
 */

eclint check with indent_size = 4 gives me many errors such as "invalid indent size: 5, expected: 4" on lines with one space more inside comments.

Support charset rule

charset signature behavior
latin1 none errors if utf-8 chars found
utf-8 none inferred default, can have bytes in 80-FF range
utf-8-bom \u00EF\u00BB\u00BF
utf-16be \u00FE\u00FF
utf-16le \u00FF\u00FE same start as utf-32le
utf-32be \u0000\u0000\u00FE\u00FF
utf-32le \u00FF\u00FE\u0000\u0000 must check before utf-16le

How to detect the character encoding of a text file

Empty file brings a wrong warning

Is this expected behavior?

# .editorconfig
insert_final_newline = true

$ touch empty.md

## Expected
$ eclint check empty.md
(no warning)
# exit code = 0

## Actual
$ eclint check empty.md
empty.md: expected final newline
# exit code = 1

My environments:

eclint v0.2.6
node.js v0.12.7
OS X 10.9.5

Cannot run any command

Hello

I cannot get eclint working.
These steps I used to install eclint:

$ ./install.sh
$ grunt build

Check command error:

$ ./bin/eclint.js check some-project/**/*
/Users/sergey/Projects/eclint/lib/commands/check.js:44
                rule.check(reporter, setting, data);
                     ^
TypeError: Object function EndOfLineRule() {
    } has no method 'check'
    at /Users/sergey/Projects/eclint/lib/commands/check.js:44:22
    at fs.js:266:14
    at Object.oncomplete (fs.js:107:15)

Infer and fix returns nothing:

$ ./bin/eclint.js infer some-project/*
$ ./bin/eclint.js fix some-project/**/*

I'm finding your application very useful. Could you help to find the working revision or fix current errors?

UPDATE

Sorry, it seems that fix command is working. But stilI there are some issues. I have been testing .editorsconfig's indent_style property on the generator-marionette source. It cannot be changed in json files, files that starts with /*jshint latedef:false */, test/tests.js file and 'use strict' lines.

Beautiful console report

I have a plugin named gulp-reporter
It was able to report errors found by gulp-eslint/gulp-jscs/gulp-jshint/gulp-tslint
I would like to push a PR to achieve compatibility with gulp-reporter

gulp-reporter demo

Invalid glob argument when running in CI or pre-commit hook

The error is as follows :

/opt/pclm/lib/ui/node_modules/vinyl-fs/lib/src/index.js:32
    throw new Error('Invalid glob argument: ' + glob);
    ^

Error: Invalid glob argument: 
    at Object.src (/opt/pclm/lib/ui/node_modules/vinyl-fs/lib/src/index.js:32:11)
    at Command._action (/opt/pclm/lib/ui/node_modules/eclint/dist/cli.js:79:22)
    at Command.parse (/opt/pclm/lib/ui/node_modules/gitlike-cli/lib/Command.js:284:18)
    at Command.tryParseSubcommand (/opt/pclm/lib/ui/node_modules/gitlike-cli/lib/Command.js:318:17)
    at Command.parse (/opt/pclm/lib/ui/node_modules/gitlike-cli/lib/Command.js:269:22)
    at Object.<anonymous> (/opt/pclm/lib/ui/node_modules/eclint/bin/eclint.js:4:5)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

My pre-commit hook is just :

#!/bin/bash

./node_modules/.bin/eclint check

It works well if I run this in a normal console.

After searching a bit, I found out that the problem comes from args.files not being empty :

check.action(function (args, options) {
        console.log(args.files);
}

If I do that, I get "undefined" if I run it from a shell, but I get a big result when I run it from my pre-commit hook :

[ Socket {
    connecting: false,
    _hadError: false,
    _handle:
     Pipe {
       bytesRead: 0,
       _externalStream: [External],
       fd: 0,
       writeQueueSize: 0,
       owner: [Circular],
       onread: [Function: onread],
       reading: false },
    _parent: null,
    _host: null,
    _readableState:
     ReadableState {
       objectMode: false,
       highWaterMark: 16384,
       buffer: [Object],
       length: 0,
       pipes: null,
       pipesCount: 0,
       flowing: null,
       ended: false,
       endEmitted: false,
       reading: false,
       sync: false,
       needReadable: true,
       emittedReadable: false,
       readableListening: false,
       resumeScheduled: false,
       destroyed: false,
       defaultEncoding: 'utf8',
       awaitDrain: 0,
       readingMore: false,
       decoder: null,
       encoding: null },
    readable: true,
    domain: null,
    _events:
     { end: [Object],
       finish: [Function: onSocketFinish],
       _socketEnd: [Function: onSocketEnd],
       pause: [Function] },
    _eventsCount: 4,
    _maxListeners: undefined,
    _writableState:
     WritableState {
       objectMode: false,
       highWaterMark: 16384,
       finalCalled: false,
       needDrain: false,
       ending: false,
       ended: true,
       finished: false,
       destroyed: false,
       decodeStrings: false,
       defaultEncoding: 'utf8',
       length: 0,
       writing: false,
       corked: 0,
       sync: true,
       bufferProcessing: false,
       onwrite: [Function: bound onwrite],
       writecb: null,
       writelen: 0,
       bufferedRequest: null,
       lastBufferedRequest: null,
       pendingcb: 0,
       prefinished: false,
       errorEmitted: false,
       bufferedRequestCount: 0,
       corkedRequestsFree: [Object] },
    writable: false,
    allowHalfOpen: false,
    _bytesDispatched: 0,
    _sockname: null,
    _pendingData: null,
    _pendingEncoding: '',
    server: null,
    _server: null,
    fd: 0,
    [Symbol(asyncId)]: 11,
    [Symbol(bytesRead)]: 0 } ]

I don't have a clue what "Sockets" have to do with that, but I think it is very likely a bug either in eclint or in git-like-cli.

Support directories on command line

It'd be neat if one could pass a directory and files inside would get enumerated. For example

├── dir
│   ├── file1.txt
│   ├── file2.txt

eclint check dir should check both files. Currently it does nothing in this case.

.eclintignore?

i would like to do eclint fix . and use a .eclintignore to ignore node modules, etc. this is similar to how i use eslint.

Generated empty locales file after execute eclint command.

Hi, I think eclint is good tool and useful to me 🎉 . Thank you for developing this tool.
Now, I tried to execute following steps and got error, So I just report it in this issue.


in macOS sierra, and os lang is ja_JP

Error case

$ npm install -g eclint
$ cd path/to/project
$ eclint ( or eclint --help or eclint --version )

After executed above steps, empty jp_JP.json is generated.

/usr/local/lib/node_modules/eclint/locales/:[]: ls

result

en.json     ja_JP.json  zh_CN.json  zh_TW.json

and that is empty file.

$ wc ja_JP.json 
       0       0       0 ja_JP.json

After executed this steps, any commands dump parse errors.

$ eclint

/usr/local/lib/node_modules/eclint/node_modules/y18n/index.js:79
    else throw err
         ^

SyntaxError: syntax error in /usr/local/lib/node_modules/eclint/locales/ja_JP.json
    at JSON.parse (<anonymous>)
    at Y18N._readLocaleFile (/usr/local/lib/node_modules/eclint/node_modules/y18n/index.js:72:25)
    at Y18N.__ (/usr/local/lib/node_modules/eclint/node_modules/y18n/index.js:26:38)
    at Object.<anonymous> (/usr/local/lib/node_modules/eclint/dist/cli.js:187:12)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/eclint/bin/eclint.js:3:11)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)

Normally case

If execute eclint check command in first, jp_JP.json file is generated that include en contents.

$ cat ja_JP.json 

{
  "Usage: $0 <command> [files...] [options]": "Usage: $0 <command> [files...] [options]",
  "Validate that file(s) adhere to .editorconfig settings": "Validate that file(s) adhere to .editorconfig settings",
  "Fix formatting errors that disobey .editorconfig settings": "Fix formatting errors that disobey .editorconfig settings",
  "Infer .editorconfig settings from one or more files": "Infer .editorconfig settings from one or more files",
  "CommandError: Missing required sub-command.": "CommandError: Missing required sub-command.",
  "Indentation Style": "Indentation Style",
  "Indentation Size (in single-spaced characters)": "Indentation Size (in single-spaced characters)",
  "Width of a single tabstop character": "Width of a single tabstop character",
  "Line ending file format (Unix, DOS, Mac)": "Line ending file format (Unix, DOS, Mac)",
  "File character encoding": "File character encoding",
  "Denotes whether whitespace is allowed at the end of lines": "Denotes whether whitespace is allowed at the end of lines",
  "Denotes whether file should end with a newline": "Denotes whether file should end with a newline",
  "Forces hard line wrapping after the amount of characters specified": "Forces hard line wrapping after the amount of characters specified",
  "Block comments start with": "Block comments start with",
  "Lines in block comment start with": "Lines in block comment start with",
  "Block comments end with": "Block comments end with"
}

After executed eclint check command in first, Any commands are normally work.

Thanks. 😄

Support block comments defined only via start and end

For example, block comments in CSS:

/* block
   comment */

This fails to pass with these options:

[*.css]
block_comment_start = /*
block_comment_end = */

Another issue with above block is that it fails the indent_size rule when it is set to 2 or 4, while I think it should be accepted. I'd suggest to disable indent_size checks inside block comments.

Remove final lines when there are more than one

  • With insert_final_newline=false all empty final lines are removed that is the expected behaviour.
  • With insert_final_newline=true a new empty line is added if it does not exist previously that is the expected behaviour.

What happens when more than one empty line exists and the end of the file and insert_final_newline=true is not well documented, and different users can have different expectations, but I think that most of the tools (i checked atom and emacs EditorConfig plugins) remove the extra lines. But eclint keeps the empty lines when there is more than one.

I think that it will be great if this tool removes the extra lines

BTW. This is a great tool.

Automatically run on all files in current directory

I think eclint should automatically run on all non-binary non-vendor files is finds in the current directory

$ eclint check

should equal to something like

$ eclint check '**/*.*' '!node_modules/**/*.*'

coupled with #45 this would make eclint a config-free tool like xo for example

Doesn’t work on Travis CI (node 0.10.x), throws Unhandled rejection TypeError

$ eclint check $(git ls-files)
Unhandled rejection TypeError: Object # h has no method 'equals'
    at detectCharset (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/linez/js/linez.js:35:41)
    at linez (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/linez/js/linez.js:19:19)
    at /home/travis/.nvm/v0.10.36/lib/node_modules/eclint/js/eclint.js:69:27
    at tryCatcher (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/promise.js:577:18)
    at Async._drainQueue (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/async.js:133:10)
    at Async.drainQueues (/home/travis/.nvm/v0.10.36/lib/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/async.js:15:14)
    at process._tickCallback (node.js:442:13)

Recursive path fails if no extension is provided

I have a Django Project with all sort of files, and I want to check all my files especially for end_of_line.
If i run eclint check **/*.html so it find all my html files in all paths (no matter how depth it is), but I can't figure out how to check all files, without have to specify the extension.

For example:

  • if I run eclint check * it only checks my root folder
  • if i run eclint check **/* it only checks the files on "root" of each child-folder BUT NOT on project folder.
  • if i run eclint check **/**/* it only checks the files on "root" of each child-child-folder BUT NOT on project folder nor on child-folder. (and so on)

Run things like eclint check **/*.* have same results as above.

What am I doing wrong?


.editorconfig

# http://editorconfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

[*.py]
indent_style = space
indent_size = 4

[*.{html,js}]
indent_style = tab

[*.{yml,scss}]
indent_style = space
indent_size = 2
$ eclint -v
1.1.5
$ npm -v
3.8.7
$ node -v
v5.11.0

[var] has no method 'equals'

It seems there's an error when trying to get BOM.
As far as I can see, this might be a problem in linez module, or the way it's implemented here.

I've got a js file that starts with jQuery.extend({
and another php file starting with <?php

This is the output I get:

$ ./node_modules/.bin/eclint fix file.js
Unhandled rejection TypeError: Object jQu has no method 'equals'

$ ./node_modules/.bin/eclint file.php
Unhandled rejection TypeError: Object <?p has no method 'equals'

Here's the backtrace for both:

at detectCharset (/node_modules/eclint/node_modules/linez/js/linez.js:35:41)
at linez (/node_modules/eclint/node_modules/linez/js/linez.js:19:19)
at /node_modules/eclint/js/eclint.js:114:27
at tryCatcher (/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/util.js:24:31)
at Promise._settlePromiseFromHandler (/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/promise.js:454:31)
at Promise._settlePromiseAt (/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/promise.js:530:18)
at Async._drainQueue (/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/async.js:182:12)
at Async._drainQueues (/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/async.js:187:10)
at Async.drainQueues (/node_modules/eclint/node_modules/editorconfig/node_modules/bluebird/js/main/async.js:15:14)
at process._tickCallback (node.js:415:13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.