@officient/readable
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -14,2 +14,3 @@ #!/usr/bin/env node | ||
const init = process.argv.includes('--init'); | ||
const help = process.argv.includes('--help'); | ||
const saveBaseLine = process.argv.includes('--save-base-line'); | ||
@@ -19,4 +20,6 @@ const disableBaseLine = process.argv.includes('--disable-base-line'); | ||
const fs = require('fs'); | ||
const helpMsg = require('../src/help'); | ||
const configLoader = require('../src/config-loader'); | ||
const lint = require('../src/lint'); | ||
const { stringify } = require('../src/utils'); | ||
@@ -67,3 +70,5 @@ process.on('uncaughtException', (err) => { | ||
if (init) { | ||
if (help) { | ||
console.log(helpMsg); | ||
} else if (init) { | ||
configLoader.init(); | ||
@@ -76,3 +81,3 @@ console.info(`Created default config in ${configLoader.fileName}`); | ||
const baseline = errors.generateBaseline(); | ||
const data = JSON.stringify(baseline, null, 2); | ||
const data = stringify(baseline); | ||
fs.writeFileSync(fileName, data); | ||
@@ -79,0 +84,0 @@ }); |
{ | ||
"name": "@officient/readable", | ||
"private": false, | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "PHP code linter", | ||
@@ -6,0 +6,0 @@ "bin": { |
@@ -9,3 +9,3 @@ ![readable](docs/logo.png) | ||
![Tests](https://github.com/officient/readable/workflows/Tests/badge.svg) | ||
[![Codeship Status for officient/readable](https://app.codeship.com/projects/4fd4eea0-676f-0138-8ef4-52f6c3762b41/status?branch=master)](https://app.codeship.com/projects/393877) | ||
@@ -18,2 +18,6 @@ ### Installation and Usage | ||
You can get the help on useage: | ||
$ npx readable --help | ||
You should then set up a configuration file: | ||
@@ -39,4 +43,10 @@ | ||
Returns 0 if no errors. Returns 1 if there are some errors. Can return 2 if some | ||
exception happend during linting. | ||
<dl> | ||
<dt>0</dt> | ||
<dd>No errors</dd> | ||
<dt>1</dt> | ||
<dd>Found errors</dd> | ||
<dt>2</dt> | ||
<dd>Unexpected behaviour</dd> | ||
</dl> | ||
@@ -50,3 +60,4 @@ ### Configuration | ||
"paths": [ | ||
"src/" | ||
"src/", | ||
"!src/vendor/" | ||
], | ||
@@ -56,9 +67,15 @@ "rules": {} | ||
``` | ||
Start a path with `!` to ignore the folder. | ||
## Baseline | ||
Create baseline file: | ||
If you have a bunch of errors and you don't want to fix them all | ||
at once, readable can ignore errors in existing code, while | ||
ensuring that new code doesn't have errors: | ||
$ npx readable --save-base-line .baseline.json | ||
Add `"baseline"` param to your `.readable.json`: | ||
will generate or update `.baseline.json` file containing the | ||
current errors. Add `"baseline"` param to your `.readable.json:` | ||
@@ -68,11 +85,9 @@ ```JSON | ||
"baseline": ".baseline.json", | ||
"paths": [ | ||
"src/" | ||
], | ||
"rules": {} | ||
"..." | ||
} | ||
``` | ||
Now errors from baseline file would be ignored. If you want to see all errors run | ||
with `--disable-base-line` flag: | ||
You can commit the changes so that readable running in other | ||
places (e.g. CI) won't complain about those errors. If you want | ||
to see all errors run with `--disable-base-line` flag: | ||
@@ -94,11 +109,11 @@ $ npx readable --disable-base-line | ||
npm run fix | ||
$ npm run fix | ||
To test: | ||
npm run test | ||
$ npm run test | ||
To update api docs: | ||
npm run docs | ||
$ npm run docs | ||
@@ -105,0 +120,0 @@ While developing you can update to latest master with |
@@ -0,0 +0,0 @@ |
{ | ||
"paths": [ | ||
"src/" | ||
"src/", | ||
"!src/vendor/" | ||
], | ||
"rules": { | ||
"argument-override": true, | ||
"empty-catch": true, | ||
@@ -20,2 +20,5 @@ "if-assigment": true, | ||
"forbidden-function-prefix": ["check"], | ||
"argument-override": { | ||
"allow-pass-by-reference": true, | ||
}, | ||
"forbidden-functions": [ | ||
@@ -22,0 +25,0 @@ "eval", "print_r", "var_export", "var_dump", "phpinfo", "exec" |
@@ -1,6 +0,3 @@ | ||
function normalisePath(path) { | ||
return path.replace(/\\/g, '/'); | ||
} | ||
const { normalisePath } = require('./utils'); | ||
// gather errors by path and message | ||
@@ -7,0 +4,0 @@ class Errors { |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -6,2 +6,4 @@ const increments = ['++', '--']; | ||
check(options, tokens, report) { | ||
const allowKey = 'allow-pass-by-reference'; | ||
const allowReference = (options && allowKey in options) ? options[allowKey] : false; | ||
tokens.matchAll('function', (token) => { | ||
@@ -12,2 +14,5 @@ const args = []; | ||
if (t1.body().startsWith('$')) { | ||
if (allowReference && t1.copy().step(true).matches('&')) { | ||
return; | ||
} | ||
args.push(t1.body()); | ||
@@ -14,0 +19,0 @@ } |
@@ -0,0 +0,0 @@ const { types } = require('../tokenize'); |
@@ -0,0 +0,0 @@ const matches = ['if', 'elseif']; |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ const matches = ['if', 'elseif']; |
@@ -0,0 +0,0 @@ const loops = ['for', 'foreach', 'do', 'while']; |
@@ -0,0 +0,0 @@ const loops = ['for', 'foreach']; |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ const matches = ['if', 'elseif', 'else', 'for', 'foreach']; |
@@ -0,0 +0,0 @@ const { dirname } = require('path'); |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ module.exports = { |
@@ -0,0 +0,0 @@ // helper to parse string and keep track |
@@ -0,0 +0,0 @@ /** |
const fs = require('fs'); | ||
const { join, extname } = require('path'); | ||
function walkDir(dir, ext) { | ||
function normalisePath(path) { | ||
return path.replace(/\\/g, '/'); | ||
} | ||
function walkDir(dir, ext, exclude) { | ||
const filesTree = fs.readdirSync(dir).map((file) => { | ||
const path = join(dir, file); | ||
if (exclude.includes(normalisePath(path))) { | ||
// we will filter it out on line 22 | ||
return 'Exclude'; | ||
} | ||
if (fs.statSync(path).isDirectory()) { | ||
return walkDir(join(path, ''), ext); | ||
return walkDir(join(path, ''), ext, exclude); | ||
} | ||
@@ -19,7 +27,28 @@ return path; | ||
function dirsTree(dirs, ext) { | ||
return dirs.map((d) => walkDir(d, ext)); | ||
const exclude = []; | ||
const include = dirs.filter((d) => { | ||
if (d.startsWith('!')) { | ||
const path = d.slice(1).replace(/\/$/, ''); | ||
exclude.push(join(path)); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
return include.map((d) => walkDir(d, ext, exclude)); | ||
} | ||
// stringify keeping order | ||
function stringify(obj) { | ||
const ordered = {}; | ||
Object.keys(obj).sort().forEach((key) => { | ||
ordered[key] = obj[key]; | ||
}); | ||
return JSON.stringify(ordered, null, 2); | ||
} | ||
module.exports = { | ||
dirsTree, | ||
stringify, | ||
normalisePath, | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
66369
29
998
116
0