handleFetchTorrentListError() { let nextInterval = config.torrentClientPollInterval || 2000; // If more than consecutive errors have occurred, then we delay the next // request. if (++this.errorCount >= 3) { nextInterval = Math.min(nextInterval + 2 ** this.errorCount, 1000 * 60); } this.deferFetchTorrentList(nextInterval); this.emit(torrentServiceEvents.FETCH_TORRENT_LIST_ERROR); }
test('lint gitignored files if filename is not given', async t => { const ignoredPath = path.resolve('fixtures/gitignore/test/foo.js'); const ignored = await readFile(ignoredPath, 'utf8'); const {results} = fn.lintText(ignored); t.true(results[0].errorCount > 0); });
const log = report => { const reporter = options.reporter ? xo.getFormatter(options.reporter) : formatterPretty; process.stdout.write(reporter(report.results)); process.exitCode = report.errorCount === 0 ? 0 : 1; }
test('do not lint gitignored files in file with negative gitignores', async t => { const cwd = path.join(__dirname, 'fixtures/negative-gitignore'); const ignoredPath = path.resolve('fixtures/negative-gitignore/bar.js'); const ignored = await readFile(ignoredPath, 'utf8'); const {results} = fn.lintText(ignored, {filename: ignoredPath, cwd}); t.is(results[0].errorCount, 0); });
test('load config in eslint to validate all rule syntax is correct', function (t) { var CLIEngine = eslint.CLIEngine var cli = new CLIEngine({ useEslintrc: false, configFile: 'eslintrc.json' }) var code = 'var foo = 1\nvar bar = function () {}\nbar(foo)\n' t.equal(cli.executeOnText(code).errorCount, 0) t.end() })
test('`ignores` option without cwd', t => { const result = fn.lintText('\'use strict\'\nconsole.log(\'unicorn\');\n', { filename: 'ignored/index.js', ignores: ['ignored/**/*.js'] }); t.is(result.errorCount, 0); t.is(result.warningCount, 0); });
test('webpack import resolver is used if webpack.config.js is found', async t => { const cwd = 'fixtures/webpack/with-config/'; const {results} = await fn.lintFiles(path.resolve(cwd, 'file1.js'), { cwd, rules: { 'import/no-unresolved': 2 } }); t.is(results[0].errorCount, 1); const errorMessage = results[0].messages[0].message; t.truthy(/Unable to resolve path to module 'inexistent'/.exec(errorMessage)); });
handleFetchTransferSummaryError() { let nextInterval = config.torrentClientPollInterval || 2000; // If more than consecutive errors have occurred, then we delay the next // request. if (++this.errorCount >= 3) { nextInterval = Math.max(nextInterval + (this.errorCount * nextInterval) / 4, 1000 * 60); } this.deferFetchTransferSummary(nextInterval); this.emit(historyServiceEvents.FETCH_TRANSFER_SUMMARY_ERROR); }
test('lint negatively gitignored files', async t => { const cwd = path.join(__dirname, 'fixtures/negative-gitignore'); const glob = path.posix.join(cwd, '*'); const {results} = await fn.lintFiles(glob, {cwd}); t.true(results[0].errorCount > 0); });
test('space option as boolean with filename', async t => { const cwd = path.join(__dirname, 'fixtures/space'); const {stdout} = await main(['--reporter=json', '--space', 'two-spaces.js'], { cwd, reject: false }); const reports = JSON.parse(stdout); // Only the specified file was checked (filename was not the value of `space`) t.is(reports.length, 1); // The default space value of 2 was expected t.is(reports[0].errorCount, 0); });
test('only accepts whitelisted extensions', async t => { // Markdown files will always produce linter errors and will not be going away const mdGlob = path.join(__dirname, '..', '*.md'); // No files should be linted = no errors const noOptionsResults = await fn.lintFiles(mdGlob, {}); t.is(noOptionsResults.errorCount, 0); // Markdown files linted (with no plugin for it) = errors const moreExtensionsResults = await fn.lintFiles(mdGlob, {extensions: ['md']}); t.true(moreExtensionsResults.errorCount > 0); });
test('webpack import resolver is used if {webpack: true}', async t => { const cwd = 'fixtures/webpack/no-config/'; const {results} = await fn.lintFiles(path.resolve(cwd, 'file3.js'), { cwd, webpack: true, rules: { 'import/no-unresolved': 2, 'import/no-webpack-loader-syntax': 0 } }); t.is(results[0].errorCount, 0); });
test('`ignores` option', t => { const result = fn.lintText('\'use strict\'\nconsole.log(\'unicorn\');\n', { filename: 'ignored/index.js', ignores: ['ignored/**/*.js'] }); t.is(result.errorCount, 0); t.is(result.warningCount, 0); });
test('do not lint eslintignored files if filename is given', async t => { const cwd = path.join(__dirname, 'fixtures/eslintignore'); const ignoredPath = path.resolve('fixtures/eslintignore/bar.js'); const ignored = await readFile(ignoredPath, 'utf8'); const {results} = fn.lintText(ignored, {filename: ignoredPath, cwd}); t.is(results[0].errorCount, 0); });
test('default `ignores`', t => { const result = fn.lintText('\'use strict\'\nconsole.log(\'unicorn\');\n', { filename: 'node_modules/ignored/index.js' }); t.is(result.errorCount, 0); t.is(result.warningCount, 0); });