node-jslint icon indicating copy to clipboard operation
node-jslint copied to clipboard

Excluding files when linting from command line

Open joetm opened this issue 10 years ago • 8 comments
trafficstars

How can I exclude files when I lint from the command line? Ideally, I would like to add an exclusion pattern to the config file, e.g. { './js/.js', '!./js/.min.js' }

joetm avatar Jun 14 '15 18:06 joetm

I am not sure about the config file, but I believe you can select the files to lint by running with that command line , because we use the "glob" package to resolve the file list

smikes avatar Jun 14 '15 19:06 smikes

I could use a glob pattern like this: ./js/*/.js But that would also include the minified files (which should not be linted). It would be beneficial if files could be excluded.

joetm avatar Jun 15 '15 09:06 joetm

Thanks - I looked into it, and I was mistaken about what the glob package can do. I thought it could handle something like **/*.js !**/*.min.js but apparently that is something that I remember from grunt-jslint, and is provided by grunt and not glob.

Are you running jslint directly from the command line, or are you using a task runner such as make, grunt, or gulp ? For the node-jslint project, I use Make like this:

SOURCES=$(shell find bin lib -name '*.js' ! -name 'jslint*.js' -print)

lint:   $(SOURCES)
    node ./bin/jslint.js --edition=es6 --this --terse $(SOURCES); echo

smikes avatar Jun 15 '15 11:06 smikes

I use gulp as task runner. I am using Windows, so make is not an option. But I just wanted to add an npm task to my project's package. I would then run it manually with npm run jslint

joetm avatar Jun 15 '15 14:06 joetm

Tricky.. I don't mostly run on Windows. What shell are you using? Cmd or powershell or..?

smikes avatar Jun 15 '15 15:06 smikes

+1 Adding the support to jslint would make such npm script portable (i.e. runnable from any shell).

ghost avatar Nov 11 '15 10:11 ghost

BTW, you can use modules like globby, glob-all, globule or simple-glob. They support the **/*.js !**/*.min.js case, IIUIC.

With just the glob module, you usually can use something like **/!(*.min).js. I am not sure why it does not work with jslint. Maybe because it depends on an older version of glob. Either way if jslint supported **/*.js !**/*.min.js it would be much more convenient.

ghost avatar Jan 03 '16 10:01 ghost

@radek-holy

node-jslint has been updated to ask for a newer version of glob. Can you see if the workaround you propose now works?

smikes avatar Aug 03 '16 03:08 smikes