liquid-linter-cli
Advanced tools
Comparing version 0.2.1 to 0.3.0
97
index.js
@@ -17,4 +17,10 @@ #!/usr/bin/env node | ||
var g_aFileExtensions = ['md', 'html', 'lqd', 'liquid']; | ||
var g_aInput = []; | ||
function addValueToCollection(p_sValue, p_aCollection) { | ||
p_aCollection.push(p_sValue); | ||
return p_aCollection; | ||
} | ||
function showFinalMessage(p_iErrorCount, p_iWarningCount) { | ||
@@ -45,5 +51,11 @@ var sErrorCount, sWarningCount; | ||
Linter.loadTags({ | ||
blocks: Commander.customBlock, | ||
tags: Commander.customTag | ||
}); | ||
p_aPaths.forEach(function (p_sPath) { | ||
var oStat, aFiles, oFileHound; | ||
var aFiles, oFileHound, oStat, sMessage; | ||
if (FileSystem.existsSync(p_sPath) === false) { | ||
@@ -53,4 +65,3 @@ | ||
console.error(Chalk.red.underline(p_sPath)); | ||
var sMessage = Util.format( | ||
sMessage = Util.format( | ||
' %d:%d %s %s', | ||
@@ -62,2 +73,4 @@ 0, | ||
); | ||
console.error(Chalk.red.underline(p_sPath)); | ||
console.error(sMessage); | ||
@@ -75,3 +88,3 @@ console.log(''); | ||
.paths(p_sPath) | ||
.ext(['htm', 'html', 'liquid', 'lqd', 'markdown', 'md']) | ||
.ext(g_aFileExtensions) | ||
.ignoreHiddenDirectories() | ||
@@ -85,31 +98,51 @@ .ignoreHiddenFiles() | ||
aFiles.forEach(function (p_sFile) { | ||
var sMessage; | ||
const sExtension = p_sFile.split('.').pop(); | ||
Linter.lintFile(p_sFile, function (p_aErrors) { | ||
// @FIXME: Use warnings if not errors | ||
// console.error(Chalk.yellow.underline(p_sPath)); | ||
// console.error(' ' + Chalk.yellow('warning') + sMessage); | ||
/* @FIXME: Individual hidden files could be given, these still need to be filtered. 2017/03/09/BMP */ | ||
if (p_aErrors.length > 0) { | ||
process.exitCode = EXIT_ERROR_LINTER; | ||
/* @NOTE: Individual files could be given that do not adhere to the extensions list */ | ||
if (g_aFileExtensions.indexOf(sExtension) === -1) { | ||
sMessage = Util.format('(file extension "%s" does not match one of "%s")', | ||
sExtension, | ||
g_aFileExtensions.join(', ') | ||
); | ||
console.error(Chalk.red.underline(p_sFile)); | ||
//@TODO: add nice padding to give different lines the same format -> ' '.repeat(4 - (p_oError.location.line + '' +p_oError.location.col).length); | ||
p_aErrors.reverse().forEach(function (p_oError) { | ||
var sMessage = Util.format( | ||
' %d:%d-%d:%d %s %s', | ||
p_oError.location.line, | ||
p_oError.location.col, | ||
p_oError.location.line, | ||
p_oError.location.col + p_oError.location.lenght, | ||
Chalk.red('error'), | ||
p_oError.message.split('\n')[0] | ||
); | ||
console.error(sMessage); | ||
iErrorCount++; | ||
}); | ||
console.log(''); | ||
} else { | ||
console.info(Chalk.green(p_sFile) + ': no issues found'); | ||
} | ||
}); | ||
sMessage = Util.format( | ||
'%s: not scanning %s', | ||
Chalk.green(p_sFile), | ||
Chalk.dim(sMessage) | ||
); | ||
console.info(sMessage); | ||
} else { | ||
Linter.lintFile(p_sFile, function (p_aErrors) { | ||
// @FIXME: Use warnings if not errors | ||
// console.error(Chalk.yellow.underline(p_sPath)); | ||
// console.error(' ' + Chalk.yellow('warning') + sMessage); | ||
if (p_aErrors.length > 0) { | ||
process.exitCode = EXIT_ERROR_LINTER; | ||
console.error(Chalk.red.underline(p_sFile)); | ||
//@TODO: add nice padding to give different lines the same format -> ' '.repeat(4 - (p_oError.location.line + '' +p_oError.location.col).length); | ||
p_aErrors.reverse().forEach(function (p_oError) { | ||
var sMessage = Util.format( | ||
' %d:%d-%d:%d %s %s', | ||
p_oError.location.line, | ||
p_oError.location.col, | ||
p_oError.location.line, | ||
p_oError.location.col + p_oError.location.lenght, | ||
Chalk.red('error'), | ||
p_oError.message.split('\n')[0] | ||
); | ||
console.error(sMessage); | ||
iErrorCount++; | ||
}); | ||
console.log(''); | ||
} else { | ||
console.info(Chalk.green(p_sFile) + ': no issues found'); | ||
} | ||
}); | ||
} | ||
}); | ||
@@ -151,3 +184,3 @@ } | ||
Commander | ||
.version('0.2.1') | ||
.version('0.3.0') | ||
.description('Linter for Liquid template files') | ||
@@ -157,2 +190,4 @@ .arguments('<paths...>') | ||
// .option('-x, --exclude <ignore-path...>', 'Paths to ignore') | ||
.option('-b, --custom-block <custom-block>', 'custom blocks to ignore (can be used multiple times)', addValueToCollection, []) | ||
.option('-t, --custom-tag <custom-tag>', 'custom tags to ignore (can be used multiple times)', addValueToCollection, []) | ||
.action(function(p_sInput) { | ||
@@ -159,0 +194,0 @@ if(g_aInput.length > 0) { |
{ | ||
"name": "liquid-linter-cli", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Command-line wrapper for the liquid template language linter.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/DealerDirect/liquid-linter-cli", |
@@ -58,2 +58,12 @@ # Liquid Linter CLI | ||
### Custom blocks and tags | ||
Liquid has support for custom [tags][liquid-tags]. The liquid-linter makes the distinction between **tags** (tags that _do not_ require an end tag) and **blocks** (tags that _do_ require an end tag). | ||
Custom tags and blocks can be passed to the linter using the `--custom-tag` and `--custom-block` flags, respectively. Both can be added multiple times, to add more than one tag or block: | ||
```bash | ||
liquid-linter --custom-block section --custom-tag button --custom-tag color /path/to/directory | ||
``` | ||
### Piping | ||
@@ -64,3 +74,3 @@ | ||
One way to achieve this is by using a combination of [find] and [xarg] | ||
One way to achieve this is by using a combination of [`find`][gnu-find] and [`xargs`][gnu-xargs]. | ||
@@ -86,7 +96,3 @@ The following example shows how to lint all files and folders in the current | ||
<pre> | ||
<span style="color:green;">./path/to/good.lqd</span>: no issues found | ||
<span style="color:red">./path/to/bad.lqd</span> | ||
23:13-23:15 <span style="color:red;">error </span> Tag '{%' was not properly terminated | ||
</pre> | ||
![screenshot of example output](./docs/example-output.png) | ||
@@ -101,3 +107,3 @@ The output is taken _directly_ from [liquid-linter]. Any weird output or incorrect | ||
We've set up a separate document for our [contribution guidelines][contributing-guidelines]. | ||
We've set up a separate document for our [contribution guidelines][contribution-guidelines]. | ||
@@ -152,28 +158,28 @@ Thank you for being involved! :heart_eyes: | ||
[project-stage-shield]: https://img.shields.io/badge/Project%20Stage-Development-yellowgreen.svg | ||
[maintenance-shield]: https://img.shields.io/maintenance/yes/2017.svg | ||
[awesome-shield]: https://img.shields.io/badge/awesome%3F-yes-brightgreen.svg | ||
[license-shield]: https://img.shields.io/github/license/dealerdirect/liquid-linter-cli.svg | ||
[versioneye-shield]: https://www.versioneye.com/user/projects/580be0d1d65a7716b613a790/badge.svg | ||
[versioneye]: https://www.versioneye.com/user/projects/580be0d1d65a7716b613a790 | ||
[version-shield]: https://img.shields.io/npm/v/liquid-linter-cli.svg | ||
[version]: https://www.npmjs.com/package/liquid-linter-cli | ||
[Cassie McKown]: https://thenounproject.com/mckowncr/ | ||
[contribution-guidelines]: CONTRIBUTING.md | ||
[potherca]: https://pother.ca/ | ||
[contributors]: https://github.com/dealerdirect/liquid-linter-cli/graphs/contributors | ||
[vacancies]: http://workingatdealerdirect.eu/?post_type=vacancy&s=&department=99 | ||
[get-in-touch]: http://workingatdealerdirect.eu/open-sollicitatie/ | ||
[workingatdealerdirecteu]: http://www.workingatdealerdirect.eu | ||
[Cassie McKown]: https://thenounproject.com/mckowncr/ | ||
[the Noun Project]: https://thenounproject.com/ | ||
[gnu-find]: https://www.gnu.org/software/findutils/manual/html_mono/find.html#Top | ||
[gnu-xargs]: https://www.gnu.org/software/findutils/manual/html_mono/find.html#Invoking-xargs | ||
[includes]: https://help.shopify.com/themes/liquid/tags/theme-tags#include | ||
[license-shield]: https://img.shields.io/github/license/dealerdirect/liquid-linter-cli.svg | ||
[liquid-lint repository]: https://github.com/tomheller/liquid-linter/issues | ||
[liquid-linter]: https://www.npmjs.com/package/liquid-linter | ||
[liquid-tags]: https://help.shopify.com/themes/liquid/tags | ||
[maintenance-shield]: https://img.shields.io/maintenance/yes/2017.svg | ||
[NPM]: https://www.npmjs.com/ | ||
[pipelines]: https://en.wikipedia.org/wiki/Pipeline_(Unix) | ||
[potherca]: https://pother.ca/ | ||
[project-stage-shield]: https://img.shields.io/badge/Project%20Stage-Development-yellowgreen.svg | ||
[the Noun Project]: https://thenounproject.com/ | ||
[vacancies]: http://workingatdealerdirect.eu/?post_type=vacancy&s=&department=99 | ||
[version-shield]: https://img.shields.io/npm/v/liquid-linter-cli.svg | ||
[version]: https://www.npmjs.com/package/liquid-linter-cli | ||
[versioneye-shield]: https://www.versioneye.com/user/projects/580be0d1d65a7716b613a790/badge.svg | ||
[versioneye]: https://www.versioneye.com/user/projects/580be0d1d65a7716b613a790 | ||
[workingatdealerdirecteu]: http://www.workingatdealerdirect.eu | ||
[Yarn]: https://yarnpkg.com/ | ||
[liquid-lint repository]: https://github.com/tomheller/liquid-linter/issues | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
270925
48
398
181
3
2