10 examples of 'eslint ignore file' in JavaScript

Every line of 'eslint ignore file' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
24function shouldIgnore(file) {
25 file = file.substring(sourceRootPath.length + 1).replace(/\\/g, "/");
26 if (file[0] === "." || file.indexOf("/.") !== -1) return true;
27 if (_.endsWith(file, ".orig")) return true;
28
29 if (templateRegex.test(file)) return false;
30 if (_.endsWith(file, "gulpfile.js") || _.endsWith(file, "Gulpfile.js") || _.endsWith(file, "tsconfig.json")) return true;
31 if (file.indexOf("node_modules/") === -1) {
32 if (_.endsWith(file, ".jade")) return true;
33 if (_.endsWith(file, ".styl")) return true;
34 if (_.endsWith(file, ".ts") && file.indexOf("typings/") === -1) return true;
35 }
36 if (_.endsWith(file, ".js") && file.indexOf("editors/") !== -1 && file.indexOf("public/") === -1) return true;
37 if (_.startsWith(file, "client")) return true;
38 if (_.startsWith(file, "scripts")) return true;
39 if (_.startsWith(file, "node_modules/browserify")) return true;
40 if (_.startsWith(file, "node_modules/brfs")) return true;
41 if (_.startsWith(file, "node_modules/vinyl-source-stream")) return true;
42 if (_.startsWith(file, "node_modules/watchify")) return true;
43 if (_.startsWith(file, "node_modules/gulp")) return true;
44 if (_.startsWith(file, "bin")) return true;
45 if (_.startsWith(file, "workbench")) return true;
46 if (_.startsWith(file, "builds") || _.startsWith(file, "projects")) return true;
47 if (file === "config.json") return true;
48 if (file === "registry.json") return true;
49 return false;
50};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

19function isIgnored(filename, ignores) {
20 return ignores.some(function (ignore) {
21 if (path.basename(filename) === ignore) {
22 return true;
23 }
24
25 if (minimatch(filename, ignore, { nocase: true })) {
26 return true;
27 }
28
29 return false;
30 });
31}
58function isIgnored(file) {
59 return gitignore.ignores(file);
60}
11function createIgnorer(ignorePath, withNodeModules) {
12 return (!ignorePath
13 ? Promise.resolve(null)
14 : getFileContentOrNull(path.resolve(ignorePath))
15 ).then(ignoreContent => _createIgnorer(ignoreContent, withNodeModules));
16}
118function shouldIgnore(root, file){
119 var relPath = path.relative(baseDir,root);
120 return !!~foldersToIgnore.indexOf(relPath)
121}
78module.exports = function ignored(gitignorefile, callback) {
79 // check if the method was called sync or asyn by checking for callback
80 if(!callback || typeof callback !== 'function') {
81 if(!gitignorefile) { // attempt to find .gitignore file in parent dir:
82 gitignorefile = path.resolve("./.gitignore");
83 } else {
84 gitignorefile = path.resolve(gitignorefile);
85 }
86 console.log("SYNC filename:"+gitignorefile);
87 console.log(' '); // blank line
88 return sync(gitignorefile);
89 }
90 else {
91 // next check if the gitignorefile parameter was supplied
92 console.log("ASYNC filename:"+gitignorefile);
93 console.log(' '); // blank line
94 fs.stat(gitignorefile, function(err, stats){
95 if(err) {
96 callback(err, []);
97 }
98 else {
99 if(!stats.isFile()) {
100 var error = { msg : "ERROR: Bad .gitignore file!" }
101 callback(error, []);
102 } else {
103 fs.readFile(gitignorefile, 'utf8', function gotfile(err, str) {
104 var list = [];
105 var lines = str.split('\n');
106 lines.forEach(function(line) {
107 line = line.trim();
108 if(line.charAt(0) === '#' || line.length === 0) {
109 // ignore comment and empty lines
110 }
111 else {
112 list.push(line);
113 }
114 });
115 callback(null, list);
116 }); // end fs.readFile
117 }
118 }
119 }); // end fs.stat
120 }
121}
90function readNPMIgnore(pkgOptions, buildOptions, callback){
91
92 if( buildOptions.ignore ){
93 callback(undefined, buildOptions.ignore);
94 return;
95 }
96
97 npmignore(path.dirname(pkgOptions.manifestPath), function(error, toIgnore){
98
99 if(error){
100 debug('Failed to read .npmignore');
101 callback();
102 return;
103 }
104
105 callback(undefined, toIgnore);
106
107 });
108
109}
70function filterFilesByIgnore(files, ignorePatterns, ignoreRules, cwd = process.cwd()) {
71 const ig = ignore().add([...ignorePatterns, ...ignoreRules])
72 const filtered = files
73 .map(raw => (path.isAbsolute(raw) ? raw : path.resolve(cwd, raw)))
74 .map(raw => path.relative(cwd, raw))
75 .filter(filePath => !ig.ignores(filePath))
76 .map(raw => path.resolve(cwd, raw))
77 return filtered
78}
122function getBuildIgnore () {
123 return fs
124 .readFileSync('.buildignore', 'utf8')
125 .split(/\r\n|\n|\r/)
126 .filter(item => {
127 if (item && item.indexOf('//') !== 0) {
128 return '!' + item
129 }
130 })
131 .map(item => '!' + item)
132}
64function getExcludeFunction(excludePath, cwd = process.cwd()) {
65 if (isFileSync(excludePath)) {
66 var ignorer = ignore()
67 ignorer.add(fs.readFileSync(excludePath, 'utf8'))
68
69 return function (changePath) {
70 var relPath = path.relative(cwd, changePath)
71 return relPath ? ignorer.ignores(relPath) : false
72 }
73 }
74
75 console.error('Unable to load file from `--exclude-path`:')
76 console.error(' ' + path.resolve(excludePath))
77 process.exit(1)
78}

Related snippets