pugjs / pug-lint

An unopinionated and configurable linter and style checker for Pug
ISC License
228 stars 51 forks source link

How to check multiple files? #144

Closed nicothin closed 5 years ago

nicothin commented 6 years ago

in my package.json:

"scripts": {
    ...
    "test": "pug-lint src/**/*.pug && npm run test:style && npm run test:editorconfig && npm run build",
    ...
  },

but when i run the command npm test I see Error: Path src/**/*.pug was not found

image

Tell me please, what did I do wrong? How do I check all the files in the folder (and subfolders)? (the pug-lint is installed locally, the global installation is not suitable)

WilliamRADFunk commented 6 years ago

I have the same problem. I don't believe this library supports globs.

It seems it focuses on just one file at a time, and that a separate task-runner (ie. Gulp) is needed to run pug-lint over each file in a */.pug glob.

I ran the same command on a single file, and it runs fine, which is why I believe it's a glob thing.

qqilihq commented 6 years ago

I came here with the same issue and can confirm that globs are not supported by pug-lint.

In case you want to run the lint task through a NPM/Yarn script, here's our simple workaround by using the glob-exec module:

{
  "scripts": {
    "lint:pug": "glob-exec './src/**/*.pug' -- \"pug-lint {{files.join(' ')}}\""
  }
}
nicothin commented 6 years ago

strange, but it does not work for me :( the command ls shows that there are *.pug files, but glob-exec does not "see" them.

nicothin@nicwin10 MINGW64 /d/projects/NTH-start-project (master)
$ npm run test:pug

> NTH-start-project@3.1.0 test:pug D:\projects\NTH-start-project
> glob-exec './src/**/*.pug' -- "ls -a ./src/ && echo files {{files.length}}"

.  ..  blocks  blocks-demo.pug  css  favicon  fonts  img  index.pug  js  pug  readme.md  scss
files 0

The reason is that I have windows or that I have crooked hands? ))

qqilihq commented 6 years ago

Sorry, didn't have any opportunity to try this on Windows yet. We're running on OS X and Linux/Docker, where it works just fine.

rtbm commented 5 years ago

Howdy! Windows don't like single-quoted arguments, use double, escape, enjoy.

{
  "scripts": {
    "lint:pug": "glob-exec \"./src/**/*.pug\" -- \"pug-lint {{files.join(' ')}}\""
  }
}
nicothin commented 5 years ago

@rtbm thank you very much!

in-in commented 4 years ago

It works for me without the extra asterisks

npx pug-lint -c .config/.pug-lintrc.json src
src/components/button/index.pug:2:1
    1| mixin button()
  > 2|  button(class=st.btn)&attributes(attributes) foobar
-------^
    3| 

Invalid indentation
Tiliavir commented 4 years ago

I chose a slightly different approach here, maybe someone finds it useful:

https://github.com/Tiliavir/mvw-creator/blob/master/ts/creator.ts, l.146

export const lintPug = () => {
  Logger.info("Starting Pug Lint");

  const PugLint = require("pug-lint");
  const ConfigFile = require("pug-lint/lib/config-file");
  const linter = new PugLint();

  linter.configure(ConfigFile.load());

  return gulp.src(config.pugLintPath) // adjust accordingly
              .pipe($.data((f: File) => {
                for (const err of linter.checkPath(f.path)) {
                  Logger.warn(`${err.msg}: ${err.filename} ${err.line}:${err.column || 0}`);
                }
              }));
};

than i expose it to npm using (https://github.com/Tiliavir/mvw-creator/blob/master/ts/cli/lint.ts):

#!/usr/bin/env node

import { lintPug } from "../creator";

lintPug();

In this specific repo I expose it in package.jsons bin - but you could call it in the scripts block as well.