Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

29 changes: 0 additions & 29 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
82 changes: 14 additions & 68 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,23 @@
name: Test
on:
push:
branches:
- main
pull_request:

on: [push, pull_request]

permissions:
contents: read

jobs:
full:
name: Node.js 20 Full
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Run tests
run: pnpm test
short:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 18
- 16
name: Node.js ${{ matrix.node-version }} Quick
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install dependencies
run: pnpm install --ignore-scripts
- name: Run unit tests
run: pnpm unit
old:
runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
node-version:
- 14
- 12
name: Node.js ${{ matrix.node-version }} Quick
os: [ubuntu-latest, windows-latest]
node-version: [lts/*, latest]
Comment thread
MoOx marked this conversation as resolved.
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v1
with:
version: 3
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: pnpm install --no-frozen-lockfile --ignore-scripts
- name: Run unit tests
run: pnpm unit
- run: npm ci
- run: npm test
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## Unreleased

- Changed: dropped support for Node.js below 18.
- Fixed: the summary now uses the singular form for a single error or warning
(`1 error`, not `1 errors`).
- Fixed: the README now states that errors are logged by default too, and that
they always make the plugin throw.
- Internal: maintenance taken over by @MoOx.
- Internal: switched from pnpm to npm.
- Internal: replaced tape with the Node.js test runner.
- Internal: replaced ESLint with oxlint and oxfmt.
- Internal: dropped `clean-publish`, `less`, `stylelint` and `strip-color` from
the development dependencies.

## 7.1

- Added better `error` message support (by Stéphane Goetz).
Expand Down Expand Up @@ -59,47 +73,61 @@
- Only log warning messages (`type: "warning"`) by default.

## 1.4.1

- Add `filter` option.
- Add blacklist functionality to `plugins` option with `!` prefix`.

## 1.3.3

- Fix regression that caused positions from sources without incoming sourcemaps not to be logged.

## 1.3.2

- Find more accurate positions of preprocessed files with sourcemaps.

## 1.3.1

- Fix Windows path bug.

## 1.3.0

- Check individual messages for distinct sources, then group messages by those sources,
instead of always using the PostCSS Result's source.
- Output empty string from `formatter` if there are no messages, instead of `undefined`.

## 1.2.1

- Handle variable and absent input sources.

## 1.2.0

- Add `noIcon` and `noPlugin` options to both reporter and formatter.

## 1.1.0

- Use PostCSS 5's line/column properties on warnings, instead of relying on the source node.

## 1.0.0

- Upgrade to PostCSS 5.

## 0.4.0

- Add `positionless` option (to both the reporter and the formatter), with default value `"first"`.
- Cleaner npm install (files specified in `package.json`).

## 0.3.1

- Remove leftover debugging log statement.

## 0.3.0

- Add `sortByPosition` option (to both the reporter and the formatter), with default value `true`.

## 0.2.0

- Alter `defaultFormatter` to use warning symbol and not repeat `# postcss-reporter`.

## 0.1.0

- First release.
70 changes: 42 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# postcss-reporter

A PostCSS plugin to `console.log()` the messages (warnings, etc.) registered by other PostCSS plugins.
[![GitHub package.json version](https://img.shields.io/github/package-json/v/postcss/postcss-reporter) ![npm downloads](https://img.shields.io/npm/dm/postcss-reporter)](https://www.npmjs.com/package/postcss-reporter)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/postcss/postcss-reporter/test.yml)](https://github.com/postcss/postcss-reporter/actions)
[![License](https://img.shields.io/github/license/postcss/postcss-reporter)](https://github.com/postcss/postcss-reporter)

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

## Purpose

Expand All @@ -11,37 +15,40 @@ So this plugin exists to read the accumulated messages (or messages from only th

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.
_By default, only warnings and errors are logged_. If you would like to see more messages, you can change the `filter` function.

## Example Output

![Example](example.png?raw=true)
![Example](https://raw.githubusercontent.com/postcss/postcss-reporter/main/example.png)

## Installation
## Install

```shell
```console
npm install --save-dev postcss postcss-reporter
```

Version 1.0.0+ is compatible with PostCSS 5+. (Earlier versions are compatible with PostCSS 4.)
Version 7.0.0+ is compatible with PostCSS 8+. (Versions 1.0.0 to 6.x are compatible with PostCSS 5+, earlier versions 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.
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](https://github.com/postcss/gulp-postcss):

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

Expand All @@ -58,17 +65,17 @@ See also `clearAllMessages`.
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
- 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:

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

**plugins** (array of strings, default = `[]`)
Expand All @@ -87,7 +94,7 @@ There are 2 ways to limit output:

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.)
By default, only messages with `type: "warning"` or `type: "error"` are logged. (Warnings 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.

Expand All @@ -100,6 +107,7 @@ 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.
An error is always thrown when at least one `error` message is logged, regardless of this option.

**sortByPosition** (boolean, default = `true`)

Expand Down Expand Up @@ -128,12 +136,12 @@ If you would like no colors in the console output, simply pass `--no-colors` whe
You can also use this module's formatter as a library, with following API:

```js
var formatter = require('postcss-reporter/lib/formatter');
var myFormatter = formatter(myOptions);
const formatter = require("postcss-reporter/lib/formatter");
const myFormatter = formatter(myOptions);
// to use defaults, just pass no options: `formatter()`
var warningLog = myFormatter({
const warningLog = myFormatter({
messages: someMessages,
source: someSource
source: someSource,
});
console.log(warningLog);
```
Expand All @@ -143,3 +151,9 @@ 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

## Contributors

Thanks goes to [these wonderful people](https://github.com/postcss/postcss-reporter/graphs/contributors)

## [License](./LICENSE)
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var reporter = require('./lib/reporter');
var reporter = require("./lib/reporter");

module.exports = reporter;
module.exports.postcss = true;
Loading
Loading