-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: (main-module) Eslinter first working version
- Loading branch information
Roy Riojas
committed
Mar 22, 2015
0 parents
commit 3ac2d05
Showing
13 changed files
with
494 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Created by .gitignore support plugin (hsz.mobi) | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- | ||
node_modules | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 0.12 | ||
- 0.10.33 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Roy Riojas | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[](https://npmjs.org/package/eslinter) | ||
[](https://travis-ci.org/royriojas/eslinter) | ||
|
||
# eslinter | ||
> Simple wrapper around eslint with support for globs and cache, so files that not changed can be skipped, if previous run passed | ||
## Motivation | ||
|
||
`eslint` cli | ||
|
||
## Install | ||
|
||
```bash | ||
npm i -g eslinter | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
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. | ||
``` | ||
|
||
## Examples | ||
|
||
```bash | ||
# validate files, easy way | ||
eslinter src/**/*.js specs/**/*.js | ||
|
||
# validate files using cache | ||
eslinter -u src/**/*.js | ||
|
||
# especify a custom formatter | ||
eslinter -f 'stylish' src/**/*.js | ||
|
||
# especify a custom formatter from node_modules | ||
eslinter -f 'node_modules/eslint-path-formatter' src/**/*.js | ||
``` | ||
|
||
**Note** | ||
|
||
The cache is only kept if the executions of the eslinter command are done with the `-u` flag. If any execution omit this flag | ||
The cache will be destroyed and be created again from scratch the next time the `-u` flag is provided | ||
|
||
## [Changelog](./changelog.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env node | ||
|
||
var main = require( '../src/main' ); | ||
var programOptions = require( '../src/options' ); | ||
|
||
var cliLauncher = require( 'clix' ); | ||
|
||
cliLauncher.launch( programOptions, function ( cli ) { | ||
main.run( cli ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"rules": { | ||
"eqeqeq": 0, | ||
"curly": 2, | ||
"quotes": [2, "single"], | ||
"strict": 0, | ||
"no-unused-expressions": 0, | ||
"no-underscore-dangle": 0, | ||
"no-unused-vars": 1, | ||
"no-spaced-func" : 0, | ||
"no-shadow": 1, | ||
"camelcase": 1, | ||
"new-cap": 1, | ||
"dot-notation": 1, | ||
"no-native-reassign": 1, | ||
"no-new": 1, | ||
"no-constant-condition": 1, | ||
"consistent-return": 1 | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"ecmaFeatures": { | ||
"jsx" : true | ||
}, | ||
"globals": { | ||
"assert": true, | ||
"it": true, | ||
"spyOn": true, | ||
"describe": true, | ||
"beforeEach": true, | ||
"afterEach": true, | ||
"stop": true, | ||
"start": true, | ||
"jQuery": true, | ||
"kno": true, | ||
"doT": true, | ||
"Element": true, | ||
"require": true, | ||
"equal": true, | ||
"notEqual": true, | ||
"ok": true, | ||
"test": true, | ||
"throws": true, | ||
"asyncTest": true, | ||
"module": true, | ||
"__shim": true, | ||
"console": true, | ||
"deepEqual": true, | ||
"checkEqual": true, | ||
"strictEqual": true, | ||
"jasmine" : true, | ||
"expect": true, | ||
"hasProperties": true, | ||
"hasMethods": true, | ||
"hasjQueryProps" : true, | ||
"browser": true, | ||
"by": true, | ||
"protractor": true, | ||
"element": true, | ||
"self": true, | ||
"Promise": true, | ||
"IDBKeyRange": true, | ||
"indexedDB": true, | ||
"chrome": true, | ||
"TEMPORARY": true, | ||
"PERSISTENT": true, | ||
"FileError": true, | ||
"Modernizr": true, | ||
"requireArr": true, | ||
"iit": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
var dispatcher = require( 'dispatchy' ); | ||
var merge = require( 'lodash.merge' ); | ||
|
||
function getErrorResults( results ) { | ||
var filtered = []; | ||
|
||
results.forEach( function ( result ) { | ||
var filteredMessages = result.messages.filter( function ( message ) { | ||
return message.severity === 2; | ||
} ); | ||
|
||
if ( filteredMessages.length > 0 ) { | ||
filtered.push( { | ||
filePath: result.filePath, | ||
messages: filteredMessages | ||
} ); | ||
} | ||
} ); | ||
|
||
return filtered; | ||
} | ||
|
||
module.exports = merge( dispatcher.create(), { | ||
lint: function ( filesSrc, opts ) { | ||
|
||
var me = this; | ||
opts = opts || {}; | ||
|
||
var files; | ||
var cfg = opts.cfg; | ||
var useCache = !!opts.useCache; | ||
|
||
filesSrc = filesSrc || []; | ||
|
||
var cache = require( 'file-entry-cache' ).create( '__eslinter__' ); | ||
|
||
if ( !useCache ) { | ||
cache.deleteCacheFile(); | ||
files = filesSrc; | ||
} else { | ||
files = cache.getUpdatedFiles( filesSrc ); | ||
} | ||
|
||
me.fire( 'eslinter:start', { | ||
filesSrc: filesSrc, | ||
files: files | ||
} ); | ||
|
||
if ( files.length === 0 ) { | ||
return { | ||
output: '', | ||
errorCount: 0 | ||
}; | ||
} | ||
|
||
var eslint = require( 'eslint' ); | ||
var engine = new eslint.CLIEngine( cfg ); | ||
|
||
var report = engine.executeOnFiles( files ); | ||
|
||
var results = report.results || []; | ||
|
||
results.forEach( function ( result ) { | ||
if ( result.errorCount > 0 || result.warningCount > 0 ) { | ||
cache.removeEntry( result.filePath ); | ||
} | ||
} ); | ||
|
||
if ( opts.quiet ) { | ||
results = getErrorResults( results ); | ||
} | ||
|
||
cache.reconcile(); | ||
|
||
var formatter = typeof opts.format === 'function' ? opts.format : engine.getFormatter( opts.format ); | ||
|
||
if ( !formatter ) { | ||
throw new Error( 'Could not find formatter: ' + opts.format ); | ||
} | ||
|
||
var output = formatter( results ); | ||
|
||
return { | ||
output: output, | ||
errorCount: report.errorCount | ||
}; | ||
} | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = console; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = process; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"name": "eslinter", | ||
"version": "1.0.0", | ||
"description": "Simple wrapper around eslint with support for globs and cache, so files that not changed can be skipped, if previous run passed", | ||
"main": "index.js", | ||
"scripts": { | ||
"beautify": "esbeautifier index.js 'src/**/*.js' 'lib/**/*.js' 'bin/**/*.js' 'specs/**/*.js'", | ||
"beautify-check": "esbeautifier -k index.js 'src/**/*.js' 'lib/**/*.js' 'bin/**/*.js' 'specs/**/*.js'", | ||
"eslint": "./bin/cli.js index.js 'src/**/*.js' 'lib/**/*.js' 'bin/**/*.js' 'specs/**/*.js'", | ||
"test": "mocha-runner 'specs/**/*.js'", | ||
"cover": "istanbul cover -x 'specs/**/*.js' mocha-runner 'specs/**/*.js' html text-summary", | ||
"watch": "npm run cover && watch-spawn -p 'specs/**/*.js' -p 'index.js' -p 'src/**/*.js' npm run cover", | ||
"lint": "npm run beautify && npm run eslint && npm test", | ||
"check": "npm run beautify-check && npm run eslint && npm test", | ||
"changelog": "changelogx -f markdown -o ./changelog.md", | ||
"install-hooks": "prepush install && changelogx install-hook" | ||
}, | ||
"bin": { | ||
"eslinter": "./bin/cli.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/royriojas/eslinter" | ||
}, | ||
"license": "MIT", | ||
"author": "Roy Riojas (http://royriojas.com)", | ||
"prepush": [ | ||
"npm run check" | ||
], | ||
"devDependencies": { | ||
"changelogx": "^1.0.10", | ||
"esbeautifier": "^2.0.3", | ||
"istanbul": "^0.3.8", | ||
"mocha-runner": "^1.0.8", | ||
"prepush": "^2.0.3", | ||
"proxyquire": "^1.4.0", | ||
"watch-spawn": "^1.0.3" | ||
}, | ||
"dependencies": { | ||
"clix": "^1.0.5", | ||
"dispatchy": "^1.0.2", | ||
"eslint": "^0.17.1", | ||
"eslint-friendly-formatter": "^1.0.5", | ||
"file-entry-cache": "^1.0.1", | ||
"glob-expand": "^0.1.0", | ||
"lodash.merge": "^3.0.3", | ||
"optionator": "^0.5.0" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/royriojas/eslinter/issues" | ||
}, | ||
"homepage": "https://github.com/royriojas/eslinter", | ||
"keywords": [ | ||
"lint", | ||
"eslint", | ||
"javascript", | ||
"code", | ||
"check", | ||
"jshint alternative", | ||
"glob", | ||
"file glob", | ||
"jsx lint", | ||
"jsx eslint" | ||
] | ||
} |
Oops, something went wrong.