Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 19, 2019
1 parent 8d6c5c5 commit 4f50816
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const runEslint = (paths, options) => {
return processReport(report, options);
};

module.exports.lintText = (str, options) => {
module.exports.lintText = (string, options) => {
options = optionsManager.preprocess(options);

if (options.overrides && options.overrides.length > 0) {
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports.lintText = (str, options) => {
}

const engine = new eslint.CLIEngine(options);
const report = engine.executeOnText(str, options.filename);
const report = engine.executeOnText(string, options.filename);

return processReport(report, options);
};
Expand All @@ -104,8 +104,8 @@ module.exports.lintFiles = (patterns, options) => {
// For silly users that don't specify an extension in the glob pattern
if (!isEmptyPatterns) {
paths = paths.filter(filePath => {
const ext = path.extname(filePath).replace('.', '');
return options.extensions.includes(ext);
const extension = path.extname(filePath).replace('.', '');
return options.extensions.includes(extension);
});
}

Expand Down
22 changes: 11 additions & 11 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ const normalizeOptions = options => {
return options;
};

const mergeWithPkgConf = options => {
const mergeWithPackageConfig = options => {
options = Object.assign({cwd: process.cwd()}, options);
options.cwd = path.resolve(options.cwd);
const conf = pkgConf.sync('xo', {cwd: options.cwd, skipOnFalse: true});
const config = pkgConf.sync('xo', {cwd: options.cwd, skipOnFalse: true});
const engines = pkgConf.sync('engines', {cwd: options.cwd});
return Object.assign({}, conf, {nodeVersion: engines && engines.node && semver.validRange(engines.node)}, options);
return Object.assign({}, config, {nodeVersion: engines && engines.node && semver.validRange(engines.node)}, options);
};

const normalizeSpaces = options => typeof options.space === 'number' ? options.space : 2;

const mergeWithPrettierConf = (options, prettierOptions) => {
const mergeWithPrettierConfig = (options, prettierOptions) => {
if ((options.semicolon === true && prettierOptions.semi === false) ||
(options.semicolon === false && prettierOptions.semi === true)) {
throw new Error(`The Prettier config \`semi\` is ${prettierOptions.semi} while XO \`semicolon\` is ${options.semicolon}`);
Expand Down Expand Up @@ -279,13 +279,13 @@ const buildConfig = options => {
name = `eslint-config-${name}`;
}

const ret = resolveFrom(options.cwd, name);
const returnValue = resolveFrom(options.cwd, name);

if (!ret) {
if (!returnValue) {
throw new Error(`Couldn't find ESLint config: ${name}`);
}

return ret;
return returnValue;
});

config.baseConfig.extends = config.baseConfig.extends.concat(configs);
Expand All @@ -301,7 +301,7 @@ const buildConfig = options => {
config.baseConfig.extends = config.baseConfig.extends.concat('prettier');
// The `prettier/prettier` rule reports errors if the code is not formatted in accordance to Prettier
config.rules['prettier/prettier'] = [
'error', mergeWithPrettierConf(options, prettier.resolveConfig.sync(options.cwd || process.cwd()) || {})
'error', mergeWithPrettierConfig(options, prettier.resolveConfig.sync(options.cwd || process.cwd()) || {})
];
// If the user has the React, Flowtype, or Standard plugin, add the corresponding Prettier rule overrides
// See https://github.com/prettier/eslint-config-prettier for the list of plugins overrrides
Expand Down Expand Up @@ -374,7 +374,7 @@ const getIgnores = options => {
};

const preprocess = options => {
options = mergeWithPkgConf(options);
options = mergeWithPackageConfig(options);
options = normalizeOptions(options);
options = getIgnores(options);
options.extensions = DEFAULT_EXTENSION.concat(options.extensions || []);
Expand All @@ -383,8 +383,8 @@ const preprocess = options => {

module.exports.DEFAULT_IGNORE = DEFAULT_IGNORE;
module.exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
module.exports.mergeWithPkgConf = mergeWithPkgConf;
module.exports.mergeWithPrettierConf = mergeWithPrettierConf;
module.exports.mergeWithPkgConf = mergeWithPackageConfig;
module.exports.mergeWithPrettierConf = mergeWithPrettierConfig;
module.exports.normalizeOptions = normalizeOptions;
module.exports.buildConfig = buildConfig;
module.exports.findApplicableOverrides = findApplicableOverrides;
Expand Down
18 changes: 9 additions & 9 deletions test/cli-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import tempWrite from 'temp-write';

process.chdir(__dirname);

const main = (args, options) => execa(path.join(__dirname, '../cli-main.js'), args, options);
const main = (arguments_, options) => execa(path.join(__dirname, '../cli-main.js'), arguments_, options);

test('fix option', async t => {
const filepath = await tempWrite('console.log()\n', 'x.js');
Expand Down Expand Up @@ -71,8 +71,8 @@ test.failing('ignores fixture', async t => {

test('ignore files in .gitignore', async t => {
const cwd = path.join(__dirname, 'fixtures/gitignore');
const err = await t.throwsAsync(main(['--reporter=json'], {cwd}));
const reports = JSON.parse(err.stdout);
const error = await t.throwsAsync(main(['--reporter=json'], {cwd}));
const reports = JSON.parse(error.stdout);
const files = reports
.map(report => path.relative(cwd, report.filePath))
.map(report => slash(report));
Expand All @@ -86,8 +86,8 @@ test('ignore explicit files when in .gitgnore', async t => {

test('negative gitignores', async t => {
const cwd = path.join(__dirname, 'fixtures/negative-gitignore');
const err = await t.throwsAsync(main(['--reporter=json'], {cwd}));
const reports = JSON.parse(err.stdout);
const error = await t.throwsAsync(main(['--reporter=json'], {cwd}));
const reports = JSON.parse(error.stdout);
const files = reports.map(report => path.relative(cwd, report.filePath));
t.deepEqual(files, ['foo.js']);
});
Expand All @@ -99,8 +99,8 @@ test('supports being extended with a shareable config', async t => {

test('quiet option', async t => {
const filepath = await tempWrite('// TODO: quiet\nconsole.log()\n', 'x.js');
const err = await t.throwsAsync(main(['--quiet', '--reporter=json', filepath]));
const [report] = JSON.parse(err.stdout);
const error = await t.throwsAsync(main(['--quiet', '--reporter=json', filepath]));
const [report] = JSON.parse(error.stdout);
t.is(report.warningCount, 0);
});

Expand All @@ -115,8 +115,8 @@ test('init option', async t => {

test('invalid node-engine option', async t => {
const filepath = await tempWrite('console.log()\n', 'x.js');
const err = await t.throwsAsync(main(['--node-version', 'v', filepath]));
t.is(err.code, 1);
const error = await t.throwsAsync(main(['--node-version', 'v', filepath]));
t.is(error.code, 1);
});

test('cli option takes precedence over config', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/gitignore/test/foo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'
import fn from '../'

test(t => {
test('main', t => {
t.is(fn('foo'), fn('foobar'))
})
4 changes: 2 additions & 2 deletions test/fixtures/project/file.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const obj = { a: 1 };
console.log(obj.a);
const object = { a: 1 };
console.log(object.a);
6 changes: 3 additions & 3 deletions test/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ test('groupConfigs', t => {
},
paths: ['/user/bar/hello.js']
}
].map(obj => {
obj.options = Object.assign(manager.emptyOptions(), obj.options);
return obj;
].map(object => {
object.options = Object.assign(manager.emptyOptions(), object.options);
return object;
}));
});

Expand Down

0 comments on commit 4f50816

Please sign in to comment.