Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
982ac3e
commit dc0c06a
Showing
16 changed files
with
506 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"curly": 0, | ||
"radix": 2, | ||
"wrap-iife": 2, | ||
"brace-style": 0, | ||
"comma-style": 2, | ||
"consistent-this": [2, "_that"], | ||
"no-lonely-if": 2, | ||
"no-nested-ternary": 2, | ||
"no-process-exit": 0, | ||
"no-spaced-func": 2, | ||
"no-use-before-define": [2, "nofunc"], | ||
"quotes": [2, "single"], | ||
"space-after-keywords": [2, "always"], | ||
"space-before-blocks": [2, "always"], | ||
"space-in-parens": [2, "never"], | ||
"space-unary-ops": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
*.log | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" | ||
- "iojs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Changelog | ||
|
||
## v0.3.1 | ||
- Fix bug causing error if warning is on root node. | ||
|
||
## v0.3.0 | ||
- Throw error instead of exiting process when `throwError: true`. | ||
|
||
## v0.2.3 | ||
- Remove async. | ||
|
||
## v0.2.0 | ||
- Change the print format slightly. | ||
- Clear warnings from postcssResult.messages after logging them (configurable with option `keepWarnings`). | ||
|
||
## v0.1.3 | ||
- Add message when exiting process with code 1 to clarify reason. | ||
|
||
## v0.1.2 | ||
- Only log if there is something to log (don't log undefined). | ||
|
||
## v0.1.1 | ||
- Only exit process if code is non-zero. | ||
|
||
## v0.1.0 | ||
- First release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
# postcss-console-log-messages | ||
Log PostCSS messages in the console | ||
# postcss-log-warnings [![Build Status](https://travis-ci.org/davidtheclark/postcss-log-warnings.svg?branch=master)](https://travis-ci.org/davidtheclark/postcss-log-warnings) | ||
|
||
Log PostCSS warnings in the console. | ||
|
||
## Purpose | ||
|
||
As of PostCSS 4.1, a single PostCSS process can accumulate warnings from all of the plugins it uses. | ||
Presumably, plugin authors want you to see those warnings. | ||
So this plugin exists to read the accumulated warnings (or warnings from only the plugins you've specified), format them for human legibility, and print them to the console. | ||
|
||
## Example Output | ||
|
||
![Example](example.png?raw=true) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install postcss-log-warnings | ||
``` | ||
|
||
## Usage | ||
|
||
Add it to your plugin list *after any plugins whose warnings you want to log*, and pass it an object of options. | ||
|
||
For example, using [gulp-postcss](https://github.com/w0rm/gulp-postcss): | ||
|
||
```js | ||
gulp.task('css', function() { | ||
return gulp.src('./src/*.css') | ||
.pipe(postcss([ | ||
bemLinter(), | ||
customProperties(), | ||
calc(), | ||
rejectAllColors(), | ||
logWarnings(myOptions) // <------ ding | ||
])) | ||
.pipe(gulp.dest('./dist')); | ||
}); | ||
``` | ||
|
||
*By default, this plugin will clear the warnings after it logs them*. Otherwise, your other plugins or your PostCSS runner might re-print the same warnings, causing some confusion. This can be changed by setting the option `{ keepWarnings: true }`. | ||
|
||
You can also use this module as a library: | ||
|
||
```js | ||
var processResult = require('postcss-log-warnings/lib/processResult'); | ||
var warningLog = processResult(postcssResult, options); | ||
``` | ||
|
||
### Options | ||
|
||
- **keepWarnings** (boolean, default = `false`) | ||
|
||
If true, the plugin will *not* clear the warnings after it logs them (by default, it will clear them). Other plugins will then have access to these warnings and might re-print them. | ||
|
||
- **plugins** (array of strings, default = `[]`) | ||
|
||
If empty, the plugin will log every warning, regardless of which plugin registered it. | ||
To limit output, name the plugins whose warnings you would like to see. | ||
For example, `{ plugins: ['postcss-bem-linter'] }` will only log warnings from the `postcss-bem-linter` plugin. | ||
|
||
- **throwError** (boolean, default = `false`) | ||
|
||
If `true`, after the plugin logs your warnings it will throw an error if it found any warnings. | ||
(Not part of the library options.) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var postcss = require('postcss'); | ||
var chalk = require('chalk'); | ||
var processResult = require('./lib/processResult'); | ||
|
||
module.exports = postcss.plugin('postcss-log-warnings', function(options) { | ||
options = options || {}; | ||
|
||
return function(css, result) { | ||
var warningLog = processResult(result, options); | ||
|
||
if (!warningLog) return; | ||
|
||
console.log(warningLog); | ||
|
||
if (options.throwError) { | ||
throw new Error(chalk.red.bold('\n** postcss-log-warnings: warnings were found **')); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
var chalk = require('chalk'); | ||
var path = require('path'); | ||
|
||
module.exports = function(postcssResult, options) { | ||
options = options || {}; | ||
options.plugins = options.plugins || []; | ||
|
||
var warnings = postcssResult.warnings(); | ||
|
||
if (!warnings.length) return undefined; | ||
|
||
var output = '\n# postcss-log-warnings\n\n'; | ||
|
||
output += chalk.bold.underline(logFrom(postcssResult.root.source.input.from)) + '\n'; | ||
|
||
var filteredWarnings = warnings.filter(shouldLog); | ||
filteredWarnings.forEach(function(w) { | ||
output += warningToString(w) + '\n'; | ||
}); | ||
|
||
// Unless user has set `keepWarnings` option, | ||
// clear all these warnings that were just stringified | ||
if (!options.keepWarnings) { | ||
postcssResult.messages = postcssResult.messages.filter(function(message) { | ||
return message.type !== 'warning'; | ||
}); | ||
} | ||
|
||
return output; | ||
|
||
function shouldLog(warning) { | ||
if (options.plugins.length && options.plugins.indexOf(warning.plugin) === -1) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
function warningToString(warning) { | ||
var str = ''; | ||
if (warning.node && warning.node.type !== 'root') { | ||
str += chalk.bold( | ||
warning.node.source.start.line + ':' + | ||
warning.node.source.start.column + '\t' | ||
); | ||
} | ||
str += warning.text; | ||
if (options.plugins.length !== 1) { | ||
str += chalk.yellow(' [' + warning.plugin + ']'); | ||
} | ||
return str; | ||
} | ||
|
||
function logFrom(f) { | ||
if (f.charAt(0) === '<') return f; | ||
return path.relative(process.cwd(), f); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "postcss-log-warnings", | ||
"version": "0.3.1", | ||
"description": "Log PostCSS warnings in the console", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "npm run lint && tape test", | ||
"visual": "node test/visual.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/davidtheclark/postcss-log-warnings.git" | ||
}, | ||
"author": { | ||
"name": "David Clark", | ||
"email": "david.dave.clark@gmail.com", | ||
"url": "http://davidtheclark.com" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/davidtheclark/postcss-log-warnings/issues" | ||
}, | ||
"homepage": "https://github.com/davidtheclark/postcss-log-warnings", | ||
"devDependencies": { | ||
"eslint": "0.20.0", | ||
"lodash": "3.8.0", | ||
"tape": "4.0.0" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.0.0", | ||
"postcss": "^4.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @define HamSandwich */ | ||
.Ham.Sandwich { | ||
color: pink; | ||
} | ||
|
||
:root a { | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('./processResult'); |
Oops, something went wrong.
dc0c06a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you just transferred this repo instead of making a copy ?
dc0c06a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was unsure that this was the right move, so I wanted to put the files here to start discussion without affecting
postcss-log-warning
. Since the new plugin will have a different name, won't I need to keep log-warnings where it is and add a deprecation notice, instead of quietly switching locations?