How to configure .eslintr.js to ignore all non-js files?
I started a .eslintignore file with the rule !**/*.js but doesn't work.
You're close. In the .eslintignore section for negating (!) (emphasis mine):
Lines preceded by ! are negated patterns that re-include a pattern that was ignored by an earlier pattern.
So, ignore everything (you can use blob, or a specific directory, etc.) and then un-ignore js files:
src/
!src/**/*.js
Related
The link https://github.com/jhades/angularjs-gulp-example/blob/master/gulpfile.js has the gulp build-js task definition using browserify paths. I don't understand the need for it... wasn't it possible just to specify the entries as entries: './js/**/*.js', and this would have caused it to search all the sub-directories as well... instead of explicitly specifying paths: ['./js/controllers', './js/services', './js/directives'], which are all sub-directories of the same parent?
Any hints appreciated.
The author is using the paths configuration to enable non-relative require calls like these:
require('todoCtrl');
require('todoStorage');
require('todoFocus');
require('todoEscape');
require('footer');
Browserify emulates Node's module resolution mechanism (which is explained here) and when Node resolves a non-relative require, it looks in node_modules. The paths option gives Browserify a list of paths that are not in node_modules that it should check (before checking node_modules) when attempting to resolve non-relative require calls.
If all of your require calls for modules in your own project use relative paths (e.g. require('./js/controllers/todoCtrl')), you won't need the paths configuration option.
Well, one simple answer seems to be the fact that **/* is not recognised by browserify! You would have to require("glob") to do that... but it's probably simpler just to use paths to specify the extra folders.
Currently I can do:
require('./frontend/src/components/SomeComponent');
But if I set the following in my webpack.config.js:
resolve: {
root: path.resolve('frontend', 'src')
}
I can instead do:
require('components/SomeComponent');
The problem is, when I don't use Webpack (eg. in a test environment) all of my imports break. According to the Babel docs, the sourceRoot property sets the "root from which all sources are relative." This made me think I could add the following to my .babelrc to fix my imports:
"sourceRoot": "frontend/src"
... but no such luck. When I do require('components/SomeComponent'); in babel-node it fails. When I just use Babel to transpile the file, the require line is the same whether or not I set a sourceRoot.
So, my question is, is there any way (with or without sourceRoot) to simulate webpack's resolve.root in Babel?
P.S. I know there are several Babel plug-ins which address this problem, but all of the ones I've seen require you to add a ~ to the require path (which of course breaks imports in Webpack).
Many project have webpack + babel, and in many projects you sometimes bypass webpack (as in your case - for tests).
In such cases, all the resolve aliases should live in babel.
There are plugins out there to allow one reading the configuration of the other (and similar plugins for eslint etc.).
While using glob patterns to find files with gulp.src, I could not see any difference in files found between ./src/**/*.js and src/**/*.js globs. What is the purpose of the ./ if there is any at all?
It's being explicit about the path beginning from the local directory. It's usually redundant, but for some shells, with certain commands, they may allow it to use different behaviors if the ./ isn't supplied, e.g. with zsh and the cd command, it will treat cd ./foo as "only go to foo if it is a subdirectory of the current directory", while cd foo will check CDPATH for alternate targets.
I saw this pattern used in a configuration file for protractor.
specs: [
'test/e2e/**/*.spec.js'
]
To mean it means "all files inside test/e2e". What kind of pattern is this? I think it's not regex because of those unescaped slashes. Especially, why is there ** in the middle, not just test/e2e/*.spec.js?
I tried using the search engine, but did not find anything useful probably because the asterisks don't work very well in search engines.
What kind of pattern is this?
It is called "glob". The module glob is a popular implementation for Node, and appears to be the one used by Protractor.
Especially, why is there "**" in the middle, not just "test/e2e/*.spec.js"?
** means it can match sub-directories. It's like a wildcard for sub-directories.
For example, test/e2e/*.spec.js would match test/e2e/example.spec.js, but not test/e2e/subdir/example.spec.js. However test/e2e/**/*.spec.js matches both.
It is called "glob" syntax. Glob is a tool which allows files to be specified using a series of wildcards.
*.js means "everything in a folder with a js extension.
** means "descendant files/folders.
**/*.js means "descendant files with a js extension in descendant folders."
test/e2e/**/*.spec.js' means the above, starting in the test/e2e/ directory.
So, for example, given this file system:
test/e2e/foo/a.spec.js <-- matches
test/e2e/foo/butter.js <-- does not include "spec.js"
test/e2e/bar/something.spec.js <-- matches
test/other/something-different.spec.js <-- not in /test/e2e
The final pattern would match:
test/e2e/foo/a.spec.js
test/e2e/bar/something.spec.js
It's a globbing pattern. Most javascript things using globbing patterns seem to be based around the glob npm package. It's worth taking a look at the documentation as there are some handy hints in there for when you have more complex situations.
The path you are asking about will match any file ending .spec.js in any subdirectory under test/e2e
I understand how brunch handles javascript files, combining them into individual output files:
files:
javascripts:
joinTo:
'javascripts/app.js': /^app/
'javascripts/vendor.js': /^vendor/
'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
the 2nd line, for example, takes all the javascript files in the /vendor/ folder and makes the vendor.js
The Regex (/^vendor/) specifies a folder path correct? Any way to have the regex apply to the file names as well? For example if there was a jquery.js and a jquery.min.js, I just want the jquery.js file included. Is this possible?
You can use functions to test against paths. With them stuff should be simple:
joinTo:
'javascripts/vendor.js': (path) ->
/^vendor/.test(path) and not /\.min\.js$/.test(path)
You can give the paths to be ignored. The regex should match complete path for files, filenames included.
paths:
public: '../deploy'
ignored: 'vendor/styles/bootstrap'
test: 'spec'
ignored key: string, regExp, function or array of them. Will check
against files that would be ignored by brunch compilator.
But as Amberlamps suggested you can give regex to exclude *.min.js files in the files .
PS:
Never tested it but in the docs somewhere it is mentioned /_spec\.\w+$/ matches for user_spec.js.
I have never used brunch before, but if it is using RegExp to find specific paths you can exclude *.min.js files using:
/^((?!vendor\/.*\.min\.js).)*$/
I used following answer as reference: Regular expression to match string not containing a word?