• Stars
    star
    154
  • Rank 233,692 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Log PostCSS messages in the console

postcss-reporter

A PostCSS plugin to console.log() the messages (warnings, etc.) registered by other PostCSS plugins.


SEEKING A NEW MAINTAINER! Interested in contributing to the ecosystem of PostCSS and Stylelint? Please open an issue if you'd like to take over maintenance of this package.


Purpose

As of PostCSS 4.1, a single PostCSS process can accumulate messages from all of the plugins it uses. Most of these messages are warnings. Presumably, plugin authors want you to see those messages. So this plugin exists to read the accumulated messages (or messages from only the plugins you've specified), format them, and print them to the console.

By default, the messages are formatted for human legibility and sorted according to the line/column positions attached to the messages. But another formatting function can be passed in with an option, and sorting can be turned off with an option.

By default, only warnings are logged. If you would like to see more messages, you can change the filter function.

Example Output

Example

Installation

npm install --save-dev postcss postcss-reporter

Version 1.0.0+ is compatible with PostCSS 5+. (Earlier versions are compatible with PostCSS 4.)

Usage

Add it to your plugin list after any plugins whose messages you want to log, and optionally pass it an object of options.

For example, using gulp-postcss:

gulp.task('css', function() {
  return gulp.src('./src/*.css')
    .pipe(postcss([
      bemLinter(),
      customProperties(),
      calc(),
      rejectAllColors(),
      reporter(myOptions) // <------ ding
    ]))
    .pipe(gulp.dest('./dist'));
});

Options

clearReportedMessages (boolean, default = false)

If true, the plugin will clear the result's messages after it logs them. This prevents other plugins, or the task runner you use, from logging the same information again and causing confusion.

See also clearAllMessages.

formatter (function, default = the default formatter)

By default, this reporter will format the messages for human legibility in the console. To use another formatter, pass a function that

  • accepts an object containing a messages array and a source string
  • returns the string to report

For example, you could write a formatter like this:

reporter({
  formatter: function(input) {
    return input.source + ' produced ' + input.messages.length + ' messages';
  }
})

plugins (array of strings, default = [])

If plugins is empty (as it is by default), the reporter will log messages from every PostCSS plugin.

There are 2 ways to limit output:

  • Whitelist: Provide an array of the plugins whose messages you would like to show. For example, { plugins: ['postcss-bem-linter'] } will only log messages from the postcss-bem-linter plugin.
  • Blacklist: Prefix all plugins in the array with ! to specify only those plugins whose messages you would like to hide. (All other plugins will be shown.) For example, { plugins: ['!postcss-bem-linter'] } will never log messages from the postcss-bem-linter plugin; but will log messages from every other plugin.

filter (function)

Provide a filter function. It receives the message object and returns a truthy or falsy value, indicating whether that particular message should be reported or not.

By default, only messages with type: "warning" are logged. (These are the messages produced when the plugin author uses PostCSS's warn() function.)

For example, function(message) { return true } will return every message, regardless of whether or not the plugin declares it as a warning.

clearAllMessages (boolean, default = false)

If true, the plugin won't pass any messages into other plugins, or the task runner you use.

See also clearReportedMessages.

throwError (boolean, default = false)

If true, after the plugin logs your messages it will throw an error if it found any warnings.

sortByPosition (boolean, default = true)

If false, messages will not be sorted by line/column position.

positionless ("first"|"last"|"any", default = "first")

By default, messages without line/column positions will be grouped at the beginning of the output. To put them at the end, instead, use "last". To not bother sorting these, use "any".

noIcon (boolean, default = false)

If true, no exclamatory triangle icons will be printed next to warnings.

noPlugin (boolean, default = false)

If true, plugin names will not be printed in brackets after messages.

How to get output without colors

If you would like no colors in the console output, simply pass --no-colors when you invoke whatever command runs this plugin. (This works because of chalk.)

Standalone formatter

You can also use this module's formatter as a library, with following API:

var formatter = require('postcss-reporter/lib/formatter');
var myFormatter = formatter(myOptions);
// to use defaults, just pass no options: `formatter()`
var warningLog = myFormatter({
  messages: someMessages,
  source: someSource
});
console.log(warningLog);

These are the formatter's options:

  • sortByPosition (boolean, default = true)
  • noIcon (boolean, default = false) - Do not print any warning exclamatory triangle icons
  • noPlugin (boolean, default = false) - Do not print plugin names

More Repositories

1

postcss

Transforming styles with JS plugins
TypeScript
27,948
star
2

autoprefixer

Parse CSS and add vendor prefixes to rules by Can I Use
JavaScript
21,460
star
3

postcss-import

PostCSS plugin to inline at-import rules content
JavaScript
1,352
star
4

postcss-nested

PostCSS plugin to unwrap nested rules like how Sass does it.
JavaScript
1,108
star
5

postcss-100vh-fix

PostCSS plugin to fix height/min-height: 100vh on iOS
JavaScript
911
star
6

postcss-cli

CLI for postcss
JavaScript
808
star
7

gulp-postcss

Pipe CSS through PostCSS processors with a single parse
JavaScript
771
star
8

sugarss

Indent-based CSS syntax for PostCSS
JavaScript
698
star
9

postcss-js

PostCSS for React Inline Styles, Free Style and other CSS-in-JS
JavaScript
643
star
10

postcss-scss

SCSS parser for PostCSS.
JavaScript
635
star
11

postcss-load-config

Autoload Config for PostCSS
JavaScript
618
star
12

postcss-custom-properties

Use Custom Properties in CSS
JavaScript
598
star
13

postcss-bem-linter

A BEM linter for postcss
JavaScript
561
star
14

postcss-mixins

PostCSS plugin for mixins
JavaScript
446
star
15

postcss-simple-vars

PostCSS plugin for Sass-like variables
JavaScript
409
star
16

postcss-url

PostCSS plugin to rebase url(), inline or copy asset.
JavaScript
373
star
17

postcss-color-function

PostCSS plugin to transform W3C CSS color function to more compatible CSS
JavaScript
323
star
18

postcss-media-minmax

Writing simple and graceful Media Queries!
JavaScript
290
star
19

postcss-plugin-boilerplate

PostCSS Plugin Boilerplate
JavaScript
220
star
20

postcss-calc

PostCSS plugin to reduce calc()
JavaScript
208
star
21

postcss-selector-parser

A CSS selector parser, integrates with postcss but does not require it.
JavaScript
196
star
22

postcss-use

Enable PostCSS plugins directly in your stylesheet.
JavaScript
148
star
23

postcss-dark-theme-class

PostCSS plugin to make dark/light theme switcher by copying styles from media query to special class
JavaScript
147
star
24

postcss-easings

PostCSS plugin to replace easing names to cubic-bezier()
JavaScript
144
star
25

postcss-focus

PostCSS plugin to add :focus selector to every :hover for keyboard accessibility
JavaScript
116
star
26

postcss-safe-parser

Fault tolerant CSS parser for PostCSS
JavaScript
115
star
27

benchmark

PostCSS benchmarks
JavaScript
114
star
28

postcss-devtools

Log execution time for each plugin in a PostCSS instance.
JavaScript
92
star
29

postcss.org

Official website for PostCSS
JavaScript
81
star
30

postcss-browser-reporter

Plugin to display warning messages right in your browser
JavaScript
75
star
31

postcss-color-rebeccapurple

PostCSS plugin to transform rebeccapurple color to rgb()
JavaScript
62
star
32

postcss-deno

Postcss for Deno
JavaScript
56
star
33

postcss-brand-colors

PostCSS plugin to insert branding colors of all the major companies
JavaScript
54
star
34

postcss-size

PostCSS plugin for size shortcut
JavaScript
52
star
35

postcss-will-change

PostCSS plugin to insert 3D hack before will-change property
JavaScript
51
star
36

postcss-color-rgba-fallback

PostCSS plugin to transform rgba() to hexadecimal.
JavaScript
50
star
37

postcss-selector-matches

PostCSS plugin to transform :matches() W3C CSS pseudo class to more compatible CSS (simpler selectors)
JavaScript
44
star
38

postcss-plugin-context

Limit a PostCSS processor to a local stylesheet context.
JavaScript
33
star
39

postcss-color-hex-alpha

Use 4 & 8 character hex color notation in CSS
JavaScript
28
star
40

postcss-color-gray

Use the gray() color function in CSS
JavaScript
27
star
41

postcss-font-variant

PostCSS plugin to transform W3C CSS font variant properties to more compatible CSS (font-feature-settings)
JavaScript
25
star
42

brand

PostCSS branding files
JavaScript
24
star
43

postcss-filter-plugins

Exclude/warn on duplicated PostCSS plugins.
JavaScript
23
star
44

postcss-parser-tests

Base tests for every PostCSS CSS parser
JavaScript
21
star
45

postcss-color-hwb

PostCSS plugin to transform W3C CSS hwb() function to more compatible CSS (rgb() or rgba()).
JavaScript
21
star
46

eslint-config-postcss

An ESLint shareable config for postcss and plugins
JavaScript
18
star
47

postcss-plugin-suggestion-box

Suggestion box for PostCSS plugins
14
star
48

postcss-relative-opacity

PostCSS plugin to add opacity to any colors with Relative Color Syntax
JavaScript
11
star
49

fly-postcss

UNMAINTAINED
10
star
50

postcss-fail-on-warn

PostCSS plugin throws a error on any warning from previous PostCSS plugins.
JavaScript
8
star
51

postcss-sharec-config

Best parctices and configs from PostCSS plugin
7
star
52

postcss-at-rule-parser

A modern CSS at rule parser in PostCSS.
TypeScript
5
star
53

postcss-color

DEPRECATED - PostCSS plugin to transform latest W3C CSS color module syntax to more compatible CSS
JavaScript
5
star
54

postcss-deno-import

postcss-import plugin for Deno
JavaScript
4
star