Skip to content

Commit

Permalink
[meta] fix some formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 14, 2021
1 parent fa3192a commit f0c1756
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 64 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -20,7 +20,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
- [`no-duplicates`]: ensure autofix avoids excessive newlines ([#2028], thanks [@ertrzyiks])
- [`extensions`]: avoid crashing on partially typed import/export statements ([#2118], thanks [@ljharb])
- [`no-extraneous-dependencies`]: add ESM intermediate package.json support] ([#2121], thanks [@paztis])
- [`no-extraneous-dependencies`]: add ESM intermediate package.json support ([#2121], thanks [@paztis])
- Use `context.getPhysicalFilename()` when available (ESLint 7.28+) ([#2160], thanks [@pmcelhaney])
- [`extensions`]/`importType`: fix isScoped treating @/abc as scoped module ([#2146], thanks [@rperello])

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unresolved.md
Expand Up @@ -6,7 +6,7 @@ as defined by standard Node `require.resolve` behavior.
See [settings](../../README.md#settings) for customization options for the resolution (i.e.
additional filetypes, `NODE_PATH`, etc.)

This rule can also optionally report on unresolved modules in CommonJS `require('./foo')` calls and AMD `require(['./foo'], function (foo){...})` and `define(['./foo'], function (foo){...})`.
This rule can also optionally report on unresolved modules in CommonJS `require('./foo')` calls and AMD `require(['./foo'], function (foo) {...})` and `define(['./foo'], function (foo) {...})`.

To enable this, send `{ commonjs: true/false, amd: true/false }` as a rule option.
Both are disabled by default.
Expand Down
21 changes: 10 additions & 11 deletions resolvers/webpack/index.js
Expand Up @@ -118,8 +118,7 @@ exports.resolve = function (source, file, settings) {

if (typeof configIndex !== 'undefined' && webpackConfig.length > configIndex) {
webpackConfig = webpackConfig[configIndex];
}
else {
} else {
webpackConfig = find(webpackConfig, function findFirstWithResolve(config) {
return !!config.resolve;
});
Expand Down Expand Up @@ -311,16 +310,16 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
/* eslint-disable */
// from https://github.com/webpack/webpack/blob/v1.13.0/lib/WebpackOptionsApply.js#L365
function makeRootPlugin(ModulesInRootPlugin, name, root) {
if(typeof root === "string")
if (typeof root === 'string') {
return new ModulesInRootPlugin(name, root);
else if(Array.isArray(root)) {
} else if (Array.isArray(root)) {
return function() {
root.forEach(function(root) {
root.forEach(function (root) {
this.apply(new ModulesInRootPlugin(name, root));
}, this);
};
}
return function() {};
return function () {};
}
/* eslint-enable */

Expand Down Expand Up @@ -436,17 +435,17 @@ function findConfigPath(configPath, packageDir) {
}

function registerCompiler(moduleDescriptor) {
if(moduleDescriptor) {
if(typeof moduleDescriptor === 'string') {
if (moduleDescriptor) {
if (typeof moduleDescriptor === 'string') {
require(moduleDescriptor);
} else if(!Array.isArray(moduleDescriptor)) {
} else if (!Array.isArray(moduleDescriptor)) {
moduleDescriptor.register(require(moduleDescriptor.module));
} else {
for(let i = 0; i < moduleDescriptor.length; i++) {
for (let i = 0; i < moduleDescriptor.length; i++) {
try {
registerCompiler(moduleDescriptor[i]);
break;
} catch(e) {
} catch (e) {
log('Failed to register compiler for moduleDescriptor[]:', i, moduleDescriptor);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/dynamic-import-chunkname.js
Expand Up @@ -69,7 +69,7 @@ module.exports = {

try {
// just like webpack itself does
vm.runInNewContext(`(function(){return {${comment.value}}})()`);
vm.runInNewContext(`(function() {return {${comment.value}}})()`);
}
catch (error) {
context.report({
Expand Down
2 changes: 1 addition & 1 deletion src/rules/first.js
Expand Up @@ -42,7 +42,7 @@ module.exports = {
const errorInfos = [];
let shouldSort = true;
let lastSortNodesIndex = 0;
body.forEach(function (node, index){
body.forEach(function (node, index) {
if (!anyExpressions && isPossibleDirective(node)) {
return;
}
Expand Down
31 changes: 16 additions & 15 deletions src/rules/no-unresolved.js
Expand Up @@ -15,35 +15,36 @@ module.exports = {
url: docsUrl('no-unresolved'),
},

schema: [ makeOptionsSchema({
caseSensitive: { type: 'boolean', default: true },
})],
schema: [
makeOptionsSchema({
caseSensitive: { type: 'boolean', default: true },
}),
],
},

create: function (context) {

function checkSourceValue(source) {
const shouldCheckCase = !CASE_SENSITIVE_FS &&
(!context.options[0] || context.options[0].caseSensitive !== false);
const shouldCheckCase = !CASE_SENSITIVE_FS
&& (!context.options[0] || context.options[0].caseSensitive !== false);

const resolvedPath = resolve(source.value, context);

if (resolvedPath === undefined) {
context.report(source,
`Unable to resolve path to module '${source.value}'.`);
}

else if (shouldCheckCase) {
context.report(
source,
`Unable to resolve path to module '${source.value}'.`
);
} else if (shouldCheckCase) {
const cacheSettings = ModuleCache.getSettings(context.settings);
if (!fileExistsWithCaseSync(resolvedPath, cacheSettings)) {
context.report(source,
`Casing of ${source.value} does not match the underlying filesystem.`);
context.report(
source,
`Casing of ${source.value} does not match the underlying filesystem.`
);
}

}
}

return moduleVisitor(checkSourceValue, context.options[0]);

},
};
2 changes: 1 addition & 1 deletion src/rules/no-unused-modules.js
Expand Up @@ -540,7 +540,7 @@ module.exports = {

const value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey;

if (typeof exportStatement !== 'undefined'){
if (typeof exportStatement !== 'undefined') {
if (exportStatement.whereUsed.size < 1) {
context.report(
node,
Expand Down
6 changes: 2 additions & 4 deletions src/rules/order.js
Expand Up @@ -47,8 +47,7 @@ function takeTokensAfterWhile(sourceCode, node, condition) {
for (let i = 0; i < tokens.length; i++) {
if (condition(tokens[i])) {
result.push(tokens[i]);
}
else {
} else {
break;
}
}
Expand All @@ -61,8 +60,7 @@ function takeTokensBeforeWhile(sourceCode, node, condition) {
for (let i = tokens.length - 1; i >= 0; i--) {
if (condition(tokens[i])) {
result.push(tokens[i]);
}
else {
} else {
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/rules/prefer-default-export.js
Expand Up @@ -69,8 +69,7 @@ module.exports = {
node.declaration.declarations.forEach(function(declaration) {
captureDeclaration(declaration.id);
});
}
else {
} else {
// captures 'export function foo() {}' syntax
specifierExportCount++;
}
Expand Down
6 changes: 2 additions & 4 deletions tests/files/foo-bar-resolver-no-version.js
Expand Up @@ -5,10 +5,8 @@ exports.resolveImport = function (modulePath, sourceFile, config) {
if (sourceFileName === 'foo.js') {
return path.join(__dirname, 'bar.jsx')
}
else if (sourceFileName === 'exception.js') {
if (sourceFileName === 'exception.js') {
throw new Error('foo-bar-resolver-v1 resolveImport test exception')
}
else {
return undefined
}
return undefined;
}
14 changes: 6 additions & 8 deletions tests/files/foo-bar-resolver-v1.js
Expand Up @@ -3,14 +3,12 @@ var path = require('path')
exports.resolveImport = function (modulePath, sourceFile, config) {
var sourceFileName = path.basename(sourceFile)
if (sourceFileName === 'foo.js') {
return path.join(__dirname, 'bar.jsx')
return path.join(__dirname, 'bar.jsx');
}
else if (sourceFileName === 'exception.js') {
throw new Error('foo-bar-resolver-v1 resolveImport test exception')
if (sourceFileName === 'exception.js') {
throw new Error('foo-bar-resolver-v1 resolveImport test exception');
}
else {
return undefined
}
}
return undefined;
};

exports.interfaceVersion = 1
exports.interfaceVersion = 1;
10 changes: 4 additions & 6 deletions tests/files/foo-bar-resolver-v2.js
Expand Up @@ -5,12 +5,10 @@ exports.resolve = function (modulePath, sourceFile, config) {
if (sourceFileName === 'foo.js') {
return { found: true, path: path.join(__dirname, 'bar.jsx') }
}
else if (sourceFileName === 'exception.js') {
if (sourceFileName === 'exception.js') {
throw new Error('foo-bar-resolver-v2 resolve test exception')
}
else {
return { found: false }
}
}
return { found: false };
};

exports.interfaceVersion = 2
exports.interfaceVersion = 2;
6 changes: 3 additions & 3 deletions tests/files/typescript.ts
Expand Up @@ -23,14 +23,14 @@ export function getFoo() : MyType {
}

export module MyModule {
export function ModuleFunction(){}
export function ModuleFunction() {}
}

export namespace MyNamespace {
export function NamespaceFunction(){}
export function NamespaceFunction() {}

export module NSModule {
export function NSModuleFunction(){}
export function NSModuleFunction() {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/newline-after-import.js
Expand Up @@ -26,7 +26,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
code: `const x = () => require('baz') && require('bar')`,
parserOptions: { ecmaVersion: 6 } ,
},
`function x(){ require('baz'); }`,
`function x() { require('baz'); }`,
`a(require('b'), require('c'), require('d'));`,
`function foo() {
switch (renderData.modalViewKey) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/no-cycle.js
Expand Up @@ -61,7 +61,7 @@ ruleTester.run('no-cycle', rule, {
options: [{ maxDepth: 1 }],
}),
test({
code: `import("./${testDialect}/depth-two").then(function({ foo }){})`,
code: `import("./${testDialect}/depth-two").then(function({ foo }) {})`,
options: [{ maxDepth: 1 }],
parser: require.resolve('babel-eslint'),
}),
Expand Down
4 changes: 2 additions & 2 deletions tests/src/rules/no-unresolved.js
Expand Up @@ -122,7 +122,7 @@ function runResolverTests(resolver) {
type: 'Literal',
}] }),
rest({
code: "import('in-alternate-root').then(function({DEEP}){});",
code: "import('in-alternate-root').then(function({DEEP}) {});",
errors: [{
message: 'Unable to resolve path to module \'in-alternate-root\'.',
type: 'Literal',
Expand All @@ -138,7 +138,7 @@ function runResolverTests(resolver) {

// check with eslint parser
testVersion('>= 7', () => rest({
code: "import('in-alternate-root').then(function({DEEP}){});",
code: "import('in-alternate-root').then(function({DEEP}) {});",
errors: [{
message: 'Unable to resolve path to module \'in-alternate-root\'.',
type: 'Literal',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/no-useless-path-segments.js
Expand Up @@ -32,7 +32,7 @@ function runResolverTests(resolver) {
parser: require.resolve('babel-eslint') }),
test({ code: 'import("..")',
parser: require.resolve('babel-eslint') }),
test({ code: 'import("fs").then(function(fs){})',
test({ code: 'import("fs").then(function(fs) {})',
parser: require.resolve('babel-eslint') }),
],

Expand Down
2 changes: 1 addition & 1 deletion utils/moduleVisitor.js
Expand Up @@ -131,7 +131,7 @@ function makeOptionsSchema(additionalProperties) {
'additionalProperties': false,
};

if (additionalProperties){
if (additionalProperties) {
for (const key in additionalProperties) {
base.properties[key] = additionalProperties[key];
}
Expand Down

0 comments on commit f0c1756

Please sign in to comment.