├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── fixture-clean.js ├── fixture-fail.js ├── index.js ├── license ├── package.json ├── readme.md ├── screenshot.png └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 14 14 | - 12 15 | - 10 16 | - 8 17 | - 6 18 | - 4 19 | steps: 20 | - uses: actions/checkout@v2 21 | - uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | - run: npm install 25 | - run: npm test 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /fixture-clean.js: -------------------------------------------------------------------------------- 1 | /* global foo */ 2 | foo(); 3 | -------------------------------------------------------------------------------- /fixture-fail.js: -------------------------------------------------------------------------------- 1 | foo(); 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const jsYaml = require('js-yaml'); 4 | const indentString = require('indent-string'); 5 | 6 | module.exports = results => { 7 | let ret = 'TAP version 13\n'; 8 | let total = 0; 9 | 10 | for (const result of results) { 11 | const messages = result.messages; 12 | 13 | if (messages.length === 0) { 14 | ret += `ok ${++total} ` + path.relative(process.cwd(), result.filePath) + '\n'; 15 | continue; 16 | } 17 | 18 | ret += messages.map(el => { 19 | let severity = 'warning'; 20 | 21 | if (el.fatal || el.severity === 2) { 22 | severity = 'error'; 23 | } 24 | 25 | const block = '---\n' + jsYaml.safeDump({ 26 | message: el.message, 27 | severity, 28 | file: result.filePath, 29 | line: el.line || 0, 30 | name: el.ruleId 31 | }) + '...'; 32 | 33 | return `not ok ${++total}\n${indentString(block, 2)}`; 34 | }).join('\n') + '\n'; 35 | } 36 | 37 | ret += `1..${total}`; 38 | 39 | return ret; 40 | }; 41 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-tap", 3 | "version": "2.0.1", 4 | "description": "TAP formatter for ESLint", 5 | "license": "MIT", 6 | "repository": "sindresorhus/eslint-tap", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "eslint", 23 | "eslint-formatter", 24 | "formatter", 25 | "reporter", 26 | "lint", 27 | "validate", 28 | "tap", 29 | "test", 30 | "protocol" 31 | ], 32 | "dependencies": { 33 | "indent-string": "^3.1.0", 34 | "js-yaml": "^3.8.4", 35 | "yamlish": "0.0.7" 36 | }, 37 | "devDependencies": { 38 | "ava": "*", 39 | "eslint": "^0.7.4", 40 | "xo": "*" 41 | }, 42 | "xo": { 43 | "esnext": true 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # eslint-tap 2 | 3 | [TAP](http://testanything.org) formatter for [ESLint](http://eslint.org) 4 | 5 | > TAP, the Test Anything Protocol, is a simple text-based interface between testing modules in a test harness. TAP started life as part of the test harness for Perl but now has implementations in C/C++, Python, PHP, Perl and probably others by the time you read this. 6 | 7 | ![](screenshot.png) 8 | 9 | 10 | ## Install 11 | 12 | ``` 13 | $ npm install --save-dev eslint-tap 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | #### ESLint CLI 20 | 21 | ``` 22 | $ eslint --format=node_modules/eslint-tap file.js 23 | ``` 24 | 25 | #### [grunt-eslint](https://github.com/sindresorhus/grunt-eslint) 26 | 27 | ```js 28 | grunt.initConfig({ 29 | eslint: { 30 | options: { 31 | format: 'node_modules/eslint-tap' 32 | }, 33 | target: ['file.js'] 34 | } 35 | }); 36 | 37 | grunt.loadNpmTasks('grunt-eslint'); 38 | grunt.registerTask('default', ['eslint']); 39 | ``` 40 | 41 | 42 | ## License 43 | 44 | MIT © [Sindre Sorhus](https://sindresorhus.com) 45 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sindresorhus/eslint-tap/b377269aa55849513e51abd1b96215b2308ff333/screenshot.png -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import {cli as eslint} from 'eslint'; 3 | 4 | test(t => { 5 | let ret = 0; 6 | const _log = console.log; 7 | 8 | console.log = str => { 9 | console.error(str); 10 | 11 | if (/TAP/.test(str) && /ok \d+ fixture-clean\.js/.test(str)) { 12 | ret += 1; 13 | } 14 | 15 | if (str.includes(` message: '''foo'' is not defined.'`)) { 16 | ret += 1; 17 | } 18 | }; 19 | 20 | eslint.execute({ 21 | _: ['tap.js', 'fixture-clean.js', 'fixture-fail.js'], 22 | format: './' 23 | }); 24 | 25 | console.log = _log; 26 | 27 | t.is(ret, 2); 28 | }); 29 | --------------------------------------------------------------------------------