eslint-formatter-mo
Advanced tools
Comparing version 1.4.0 to 1.4.1
118
lib/index.js
@@ -1,5 +0,117 @@ | ||
import { createFormatter } from './formatter.js' | ||
/* eslint-disable no-magic-numbers */ | ||
const path = require( 'path' ) | ||
const chalk = require( 'chalk' ) | ||
const plur = require( 'plur' ) | ||
const stringWidth = require( 'string-width' ) | ||
const gradient = require( 'gradient-string' ) | ||
const link = require( 'terminal-link' ) | ||
const { locate } = require( './locator' ) | ||
const theme = process.env.MO_THEME ?? 'one-dark-pro' | ||
module.exports = function ( results ) { | ||
let totalErrorCount = 0 | ||
let totalWarningCount = 0 | ||
let autoFixableCount = 0 | ||
export default createFormatter(theme) | ||
const lines = [] | ||
results | ||
.forEach( result => { | ||
const { | ||
filePath, | ||
source, | ||
output, | ||
errorCount, | ||
warningCount, | ||
messages = [] | ||
} = result | ||
if ( errorCount + warningCount === 0 ) { | ||
return | ||
} | ||
totalErrorCount = totalErrorCount + errorCount | ||
totalWarningCount = totalWarningCount + warningCount | ||
const errorSummary = errorCount > 0 ? | ||
chalk.red.bold( errorCount + ' ' + plur( 'error', errorCount ) ) : | ||
'' | ||
const warningSummary = warningCount > 0 ? | ||
chalk.yellow.bold( | ||
`${ warningCount } ${ plur( 'warning', warningCount ) }` | ||
) : | ||
'' | ||
const relativePath = path.relative( '.', filePath ) | ||
const basename = path.basename( relativePath ) | ||
const dirname = path.dirname( relativePath ) + path.sep | ||
const formattedPath = chalk.dim( dirname ) + chalk.dim.bold( basename ) | ||
let header = '\n ' + link( formattedPath, `file://${ filePath }`, { | ||
fallback: () => formattedPath | ||
} ) + | ||
` 🔥${ errorCount > 0 ? ' ' : '' }` + | ||
[ errorSummary, warningSummary ].join( ' ' ) + | ||
`🔥\n` | ||
const divider = chalk.dim( '─'.repeat( stringWidth( header ) ) ) | ||
header = divider + header + divider | ||
lines.push( header ) | ||
const locations = messages.map( m => { | ||
let { message } = m | ||
message = message.replace( | ||
/\B`(.*?)`\B|\B'(.*?)'\B/g, | ||
( m, p1, p2 ) => chalk.bold( p1 || p2 ) | ||
) | ||
message = message.replace( /\s+$/, '' ) | ||
if ( m.fix ) { | ||
autoFixableCount = autoFixableCount + 1 | ||
} | ||
const severity = ( m.fatal || m.severity === 2 || m.severity === 'error' ) ? | ||
'error' : | ||
'warning' | ||
const line = Number( m.line || 0 ) | ||
const column = Number( m.column || 0 ) | ||
return { | ||
severity, | ||
message, | ||
line, | ||
column, | ||
fixable: Boolean( m.fix ), | ||
ruleId: m.ruleId, | ||
} | ||
} ) | ||
// Parsing error(e.g. using ts rules but missing tsconfig.json) | ||
if ( | ||
locations.length === 1 && | ||
locations[ 0 ].line === 0 && | ||
locations[ 0 ].column === 0 | ||
) { | ||
lines.push( `${ chalk.red( '✖' ) } ${ locations[ 0 ].message }` ) | ||
} else if ( source || output ) { | ||
try { | ||
const codeframe = locate( source || output, locations ) | ||
lines.push( codeframe ) | ||
} catch ( e ) { | ||
console.log( e ) | ||
} | ||
} | ||
} ) | ||
if ( totalErrorCount + totalWarningCount > 0 ) { | ||
const totalErrorMessage = chalk.redBright( ` ${ chalk.bold( totalErrorCount ) } ${ plur( 'error', totalErrorCount ) }` ) | ||
const totalWarningMessage = chalk.yellowBright( ` ${ chalk.bold( totalWarningCount ) } ${ plur( 'warning', totalWarningCount ) }` ) | ||
const totalFixableMessage = chalk.greenBright( ` ${ chalk.bold( autoFixableCount ) } ${ plur( 'auto-fixable', autoFixableCount ) } ( with the \`--fix\` flag )` ) | ||
const maxLen = stringWidth( totalFixableMessage ) + 1 | ||
return `\n${ lines.join( '\n' ) }\n` + | ||
`${ gradient.fruit( `─`.repeat( maxLen ) ) }\n` + | ||
`${ totalErrorMessage }\n${ totalWarningMessage }\n${ totalFixableMessage }\n` + | ||
`${ gradient.cristal( `─`.repeat( maxLen ) ) }\n` | ||
} | ||
return '' | ||
} |
@@ -1,4 +0,6 @@ | ||
import chalk from 'chalk' | ||
/* eslint-disable no-magic-numbers */ | ||
const chalk = require( 'chalk' ) | ||
const emphasize = require( 'emphasize' ) | ||
function locate( source, locations, highlight ) { | ||
function locate( source, locations ) { | ||
let lines = source.split( '\n' ) | ||
@@ -16,3 +18,12 @@ | ||
const formattedLines = highlight(source).split('\n') | ||
const formattedLines = emphasize.highlight( 'js', source, { | ||
keyword: chalk.magenta, | ||
built_in: chalk.cyan, // eslint-disable-line | ||
string: chalk.green, | ||
number: chalk.green, | ||
literal: chalk.green, | ||
'class': chalk.yellow, // eslint-disable-line | ||
'function': chalk.reset.white, // eslint-disable-line | ||
params: chalk.reset.white, | ||
} ).value.split( '\n' ) | ||
@@ -151,4 +162,2 @@ return lines | ||
export { | ||
locate | ||
} | ||
exports.locate = locate |
{ | ||
"name": "eslint-formatter-mo", | ||
"description": "Good-lookin' ESLint formatter for delightful readability", | ||
"version": "1.4.0", | ||
"type": "module", | ||
"exports": "./lib/index.js", | ||
"version": "1.4.1", | ||
"main": "lib/index.js", | ||
"files": [ | ||
@@ -11,6 +10,8 @@ "lib" | ||
"scripts": { | ||
"fixture": "eslint fixtures -f mo", | ||
"lint": "eslint lib -f mo", | ||
"lint:fix": "eslint lib -f mo --fix" | ||
"fixture": "eslint fixtures -f ./", | ||
"lint": "eslint lib -f ./" | ||
}, | ||
"eslintConfig": { | ||
"extends": "mo" | ||
}, | ||
"repository": { | ||
@@ -36,10 +37,8 @@ "type": "git", | ||
"dependencies": { | ||
"chalk": "^5.4.1", | ||
"gradient-string": "^3.0.0", | ||
"plur": "^5.1.0", | ||
"string-width": "^7.2.0", | ||
"terminal-link": "^3.0.0", | ||
"shiki": "^1.26.1", | ||
"@shikijs/themes": "^1.26.1", | ||
"@shikijs/langs": "^1.26.1" | ||
"chalk": "^3.0.0", | ||
"emphasize": "^4.2.0", | ||
"gradient-string": "^1.2.0", | ||
"plur": "^4.0.0", | ||
"string-width": "^4.2.0", | ||
"terminal-link": "^2.1.1" | ||
}, | ||
@@ -49,15 +48,7 @@ "devDependencies": { | ||
"@semantic-release/git": "^10.0.1", | ||
"eslint": "^9", | ||
"eslint": "^8.1.0", | ||
"eslint-config-mo": "^0.5.2", | ||
"semantic-release": "^19.0.3", | ||
"@eslint/js": "^9.17.0", | ||
"typescript-eslint": "^8.19.0", | ||
"eslint-plugin-import-x": "^4.6.1", | ||
"globals": "^15.14.0", | ||
"eslint-plugin-simple-import-sort": "^12.1.1" | ||
"semantic-release": "^19.0.3" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"packageManager": "pnpm@9.15.1" | ||
} |
@@ -14,7 +14,2 @@ # eslint-formatter-mo | ||
> [!NOTE] | ||
> This library was moved to ESM from v2. | ||
> | ||
> If ESM doesn't work well with your Node.js version, check the 1.x version for CJS compatibility. | ||
# Features | ||
@@ -29,7 +24,14 @@ | ||
- 📋 Total summary | ||
- 🥳 **Support 50+ VSCode Syntax themes (New feature from v2)** | ||
# Installation | ||
```shell | ||
```bash | ||
yarn add eslint-formatter-mo --dev | ||
``` | ||
or | ||
```bash | ||
npm i eslint-formatter-mo -D | ||
@@ -46,25 +48,4 @@ ``` | ||
See [ESLint Formatters](https://eslint.org/docs/latest/use/formatters/#eslint-formatters) for detail | ||
See [ESLint Formatters](https://eslint.org/docs/user-guide/formatters/#eslint-formatters) for detail | ||
# Themes | ||
Thanks to [shiki](https://github.com/shikijs/shiki), we now support 50+ VSCode syntax themes in v2. | ||
And you can choose your favorite theme by specifying `MO_THEME` environment variable. | ||
```shell | ||
MO_THEME=<theme_id> eslint [patterns] -f mo | ||
``` | ||
theme_id | preview | | ||
---------|---------- | ||
one-dark-pro | <img src="./media/themes/one-dark-pro.jpg" alt="one-dark-pro" width="360" /> | ||
dracula | <img src="./media/themes/dracula.jpg" alt="dracula" width="360" /> | ||
night-owl | <img src="./media/themes/night-owl.jpg" alt="night-owl" width="360" /> | ||
vitesse-dark | <img src="./media/themes/vitesse-dark.jpg" alt="vitesse-dark" width="360" /> | ||
nord | <img src="./media/themes/nord.jpg" alt="nord" width="360" /> | ||
... | ... | ||
[Here](https://shiki.style/themes) you can find all the 50+ themes. | ||
# More screenshots | ||
@@ -71,0 +52,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
6
5
0
0
11748
5
232
57
No
+ Addedemphasize@^4.2.0
+ Addedansi-escapes@4.3.2(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@3.2.14.3.0(transitive)
+ Addedchalk@2.4.23.0.04.1.2(transitive)
+ Addedcolor-convert@1.9.32.0.1(transitive)
+ Addedcolor-name@1.1.31.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedemphasize@4.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfault@1.0.4(transitive)
+ Addedformat@0.2.2(transitive)
+ Addedgradient-string@1.2.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhighlight.js@10.4.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlowlight@1.17.0(transitive)
+ Addedplur@4.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedterminal-link@2.1.1(transitive)
+ Addedtinygradient@0.4.3(transitive)
+ Addedtype-fest@0.21.3(transitive)
- Removed@shikijs/langs@^1.26.1
- Removed@shikijs/themes@^1.26.1
- Removedshiki@^1.26.1
- Removed@shikijs/core@1.29.1(transitive)
- Removed@shikijs/engine-javascript@1.29.1(transitive)
- Removed@shikijs/engine-oniguruma@1.29.1(transitive)
- Removed@shikijs/langs@1.29.1(transitive)
- Removed@shikijs/themes@1.29.1(transitive)
- Removed@shikijs/types@1.29.1(transitive)
- Removed@shikijs/vscode-textmate@10.0.1(transitive)
- Removed@types/hast@3.0.4(transitive)
- Removed@types/mdast@4.0.4(transitive)
- Removed@types/unist@3.0.3(transitive)
- Removed@ungap/structured-clone@1.2.1(transitive)
- Removedansi-escapes@5.0.0(transitive)
- Removedansi-regex@6.1.0(transitive)
- Removedccount@2.0.1(transitive)
- Removedchalk@5.4.1(transitive)
- Removedcharacter-entities-html4@2.1.0(transitive)
- Removedcharacter-entities-legacy@3.0.0(transitive)
- Removedcomma-separated-tokens@2.0.3(transitive)
- Removeddequal@2.0.3(transitive)
- Removeddevlop@1.1.0(transitive)
- Removedemoji-regex@10.4.0(transitive)
- Removedemoji-regex-xs@1.0.0(transitive)
- Removedget-east-asian-width@1.3.0(transitive)
- Removedgradient-string@3.0.0(transitive)
- Removedhast-util-to-html@9.0.4(transitive)
- Removedhast-util-whitespace@3.0.0(transitive)
- Removedhtml-void-elements@3.0.0(transitive)
- Removedmdast-util-to-hast@13.2.0(transitive)
- Removedmicromark-util-character@2.1.1(transitive)
- Removedmicromark-util-encode@2.0.1(transitive)
- Removedmicromark-util-sanitize-uri@2.0.1(transitive)
- Removedmicromark-util-symbol@2.0.1(transitive)
- Removedmicromark-util-types@2.0.1(transitive)
- Removedoniguruma-to-es@2.3.0(transitive)
- Removedplur@5.1.0(transitive)
- Removedproperty-information@6.5.0(transitive)
- Removedregex@5.1.1(transitive)
- Removedregex-recursion@5.1.1(transitive)
- Removedregex-utilities@2.3.0(transitive)
- Removedshiki@1.29.1(transitive)
- Removedspace-separated-tokens@2.0.2(transitive)
- Removedstring-width@7.2.0(transitive)
- Removedstringify-entities@4.0.4(transitive)
- Removedstrip-ansi@7.1.0(transitive)
- Removedterminal-link@3.0.0(transitive)
- Removedtinygradient@1.1.5(transitive)
- Removedtrim-lines@3.0.1(transitive)
- Removedtype-fest@1.4.0(transitive)
- Removedunist-util-is@6.0.0(transitive)
- Removedunist-util-position@5.0.0(transitive)
- Removedunist-util-stringify-position@4.0.0(transitive)
- Removedunist-util-visit@5.0.0(transitive)
- Removedunist-util-visit-parents@6.0.1(transitive)
- Removedvfile@6.0.3(transitive)
- Removedvfile-message@4.0.2(transitive)
- Removedzwitch@2.0.4(transitive)
Updatedchalk@^3.0.0
Updatedgradient-string@^1.2.0
Updatedplur@^4.0.0
Updatedstring-width@^4.2.0
Updatedterminal-link@^2.1.1