From 2fb8907f5dda3001c9e38bc8bb915029b37e7eb2 Mon Sep 17 00:00:00 2001 From: David Waterston Date: Mon, 13 Apr 2015 17:04:51 +0100 Subject: [PATCH] Initial commit --- .editorconfig | 17 +++++++++ .eslintrc | 67 ++++++++++++++++++++++++++++++++++++ .gitignore | 3 ++ CHANGELOG.md | 8 +++++ LICENSE | 22 ++++++++++++ README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 1 + package.json | 34 ++++++++++++++++++ summary.js | 56 ++++++++++++++++++++++++++++++ 9 files changed, 303 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100755 LICENSE create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json create mode 100644 summary.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d5d98af --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# This file is for unifying the coding style for different editors and IDEs +# http://EditorConfig.org + +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 4 + +[*.{js,json}] +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8c83d81 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,67 @@ +{ + // How to read the config: + // + // * 0 - rule is disabled. + // * 1 - rule is enabled but warnings will not affect the ESLint exit code. + // * 2 - rule is enabled and warnings will result in a non-zero ESLint exit code. + // + // These rules are compatible with ESLint version 0.16.0 and up. + // Detailed info about each of these rules can be found at http://eslint.org/docs/rules. + + "env": { + "node": true + }, + "rules": { + "block-scoped-var": 2, + "brace-style": [2, "1tbs", {"allowSingleLine": false}], + "comma-style": [2, "last"], + "consistent-return": 2, + "consistent-this": [0, "self"], + "default-case": 2, + "func-style": [2, "expression"], + "guard-for-in": 2, + "indent": [2, 4, {indentSwitchCase: true}], + "max-len": [2, 150], + "max-nested-callbacks": [2, 3], + "max-statements": [2, 40], + "no-array-constructor": 2, + "no-console": 2, + "no-constant-condition": 2, + "no-div-regex": 2, + "no-else-return": 2, + "no-eq-null": 2, + "no-floating-decimal": 2, + "no-inline-comments": 2, + "no-lonely-if": 2, + "no-multiple-empty-lines": [2, {"max": 3}], + "no-nested-ternary": 2, + "no-process-env": 2, + "no-reserved-keys": 2, + "no-return-assign": 2, + "no-self-compare": 2, + "no-shadow": 0, + "no-sync": 2, + "no-undefined": 2, + "no-void": 2, + "no-warning-comments": [2, { "terms": ["todo", "note", "fixme", "changes", "future"], "location": "start" }], + "operator-assignment": [2, "always"], + "quote-props": [2, "as-needed"], + "quotes": [2, "single"], + "radix": 2, + "semi": [2, "always"], + "sort-vars": [2, { "ignoreCase": false }], + "space-after-function-name": [2, "never"], + "space-after-keywords": [2, "always", {"checkFunctionKeyword": false}], + "space-before-blocks": [2, "always"], + "space-in-brackets": [2, "never"], + "space-in-parens": [2, "never"], + "space-infix-ops": 2, + "space-return-throw-case": 2, + "space-unary-ops": [2, { "words": true, "nonwords": false }], + "spaced-line-comment": [2, "always"], + "strict": [2, "global"], + "vars-on-top": 2, + "wrap-iife": [2, "outside"], + "wrap-regex": 2 + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0fa49e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/node_modules/ + +.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..708dcd5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Change Log +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [1.0.0] - 2015-04-13 + +### Added +- Initial release. diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2275573 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 David Waterston + +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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..c89533f --- /dev/null +++ b/README.md @@ -0,0 +1,95 @@ +##A minimal [ESLint](http://eslint.org) custom formatter (reporter) that displays one summary line for all files processed. + + + + + + + +A minimal [ESLint](http://eslint.org) custom formatter (reporter) that displays one summary line for all files processed. The summary line shows the number of files processed, the number of files passed linting (no errors or warnings) and the number of warning and/or errors (if there were any). Use this formatter when you simply want to verify the overall lint status of your project on Git pre-push, etc. + + +## Install + +```sh +$ npm install --save-dev eslint-summary +``` + + +## Getting started + +Use it with: + +#### [ESLint CLI](http://eslint.org/docs/user-guide/command-line-interface) + +```sh +$ eslint --format node_modules/eslint-summary/summary.js *.js +``` + +#### [grunt-eslint](https://github.com/sindresorhus/grunt-eslint/) + +```js +grunt.initConfig({ + eslint: { + options: { + format: require('eslint-summary') + }, + target: ['*.js'] + } +}); + +grunt.loadNpmTasks('grunt-eslint'); +grunt.registerTask('default', ['eslint']); +``` + + +## Compatibility +This extension has been tested and confirmed to work with ESLint versions 0.18.0 and later. + + +## Example output +ESLint-Summary in action + + +## Release History +See the [change log](https://github.com/davidwaterston/eslint-summary/blob/master/CHANGELOG.md) file for more details. + + +## Verifying Releases +I use Semantic Versioning to number releases. Each release is tagged with the appropriate version number and signed using Gnu Privacy Guard (GPG). The public key used to sign releases is +``` +Name: David Waterston +Email: david@davidwaterston.com +Key ID: A7AD9C85 +Signature: 71A9 DC13 447A 1E4F C6EB 5D64 DE08 A991 A7AD 9C85 +``` +This public key is included in the repository with a SHA1 of 16d013451476fa4a1a67d6ad4b90583e205b53b1. +After cloning the repo, and assuming you have GPG installed correctly, you can import this key into your keychain +``` +git cat-file blob pubkey | gpg --import +``` +When this public key is successfully imported, you can use it to verify the integrity of any of the tagged releases of this repo +``` +git tag -v v1.0.0 +``` +which should produce output similar to: +``` +object 04f37a55784c1f3abc2cf927a935a488aa954035 +type commit +tag v1.0.0 +tagger David Waterston 1427387056 +0000 + +Initial commit + +This is just an example so don't get fixated on the details, what matters is the signature! +gpg: Signature made Thu 26 Mar 16:24:16 2015 GMT using RSA key ID A7AD9C85 +gpg: Good signature from "David Waterston " [ultimate] +``` +The important thing to notice here is that the RSA key ID matches mine (A7AD9C85) and the line that says that this is a good signature. + +The public key can further be verified by checking the details held on pgp.mit.edu. + + +## License +Copyright (c) 2015 David Waterston. All rights reserved. +Distributed under an MIT license. See the [LICENSE](https://github.com/davidwaterston/eslint-summary/blob/master/LICENSE) file for more details. diff --git a/index.js b/index.js new file mode 100644 index 0000000..2b2cc72 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require('path').join(__dirname, 'summary.js'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..8801a75 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "eslint-summary", + "version": "1.0.0", + "description": "Minimal ESLint formatter (reporter) that displays only one summary line.", + "keywords": [ + "eslint", + "formatter", + "reporter", + "lint", + "validate" + ], + "license": "MIT", + "author": { + "name": "David Waterston", + "email": "david@davidwaterston.com", + "url": "http://dvolvr.davidwaterston.com" + }, + "repository" : + { + "type" : "git", + "url" : "https://github.com/davidwaterston/eslint-summary.git" + }, + "files": [ + "index.js", + "summary.js" + ], + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "chalk": "^1.0.0", + "text-table": "^0.2.0" + } +} diff --git a/summary.js b/summary.js new file mode 100644 index 0000000..524aa39 --- /dev/null +++ b/summary.js @@ -0,0 +1,56 @@ +'use strict'; + +var chalk = require('chalk'); +var table = require('text-table'); + +var pluralize = function(word, count) { + var plural = count === 1 ? word : word + 's'; + return plural; +}; + +module.exports = function(results) { + + var errorColor = 'red'; + var warningColor = 'yellow'; + + var errorCount = 0; + var fileCount; + var failureCount = 0; + var passCount = 0; + var warningCount = 0; + + var summaryLineArray; + + + results.forEach(function(result) { + + var messages = result.messages; + + if (messages.length === 0) { + passCount++; + } else { + failureCount++; + warningCount += result.warningCount; + errorCount += result.errorCount; + } + + }); + + fileCount = passCount + failureCount; + + summaryLineArray = [ + chalk.bold(fileCount + ' ' + pluralize('file', fileCount) + ' checked.'), + chalk.bold(passCount + ' passed.'), + chalk.bold(failureCount + ' failed.') + ]; + + if (warningCount || errorCount) { + summaryLineArray.push(chalk[warningColor].bold(warningCount + ' ' + pluralize('warning', warningCount) + '.')); + summaryLineArray.push(chalk[errorColor].bold(errorCount + ' ' + pluralize('error', errorCount) + '.')); + } + + return '\n' + + table([summaryLineArray]) + + '\n'; + +};