danger-plugin-no-console
Version:
Danger plugin to prevent merging code that still has `console.log`s inside it.
84 lines (68 loc) • 2.89 kB
HTML
<html>
<head>
<meta charset="utf-8">
<base data-ice="baseUrl" href="../../">
<title data-ice="title">src/index.js | API Document</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
<script src="script/prettify/prettify.js"></script>
<script src="script/manual.js"></script>
</head>
<body class="layout-container" data-ice="rootContainer">
<header>
<a href="./">Home</a>
<a href="identifiers.html">Reference</a>
<a href="source.html">Source</a>
<a data-ice="repoURL" href="https://github.com/withspectrum/danger-plugin-no-console.git" class="repo-url-github">Repository</a>
<div class="search-box">
<span>
<img src="./image/search.png">
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
</span>
<ul class="search-result"></ul>
</div>
</header>
<nav class="navigation" data-ice="nav"><div>
<ul>
<li data-ice="doc"><span data-ice="kind" class="kind-function">F</span><span data-ice="name"><span><a href="function/index.html#static-function-noConsole">noConsole</a></span></span></li>
</ul>
</div>
</nav>
<div class="content" data-ice="content"><h1 data-ice="title">src/index.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">const PATTERN = /console\.(log|error|warn|info)/g;
/**
* Danger plugin to prevent merging code that still has `console.log`s inside it.
*/
export default async function noConsole(options = {}) {
const whitelist = options.whitelist || [];
if (!Array.isArray(whitelist)) throw new Error('[danger-plugin-no-console] whitelist option has to be an array.');
const files = danger.git.modified_files.concat(danger.git.created_files)
const contents = await Promise.all(
files.map(file => danger.github.utils.fileContents(file).then(content => ({
file,
content,
})))
)
contents.forEach(({ file, content }) => {
let matches = content.match(PATTERN);
if (!matches) return;
matches = matches.filter(match => !whitelist.includes(PATTERN.exec(match)[1]));
if (matches.length === 0) return;
fail(`${matches.length} console statement(s) left in ${file}.`);
})
}
</code></pre>
</div>
<footer class="footer">
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.5.2)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>
<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>