Skip to content

Commit

Permalink
Replace pattern for callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Jul 23, 2021
1 parent 3f88d46 commit 8c3aafa
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/core/packagePath.js
Expand Up @@ -4,7 +4,7 @@ import readPkgUp from 'read-pkg-up';


export function getContextPackagePath(context) {
return getFilePackagePath((context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename());
return getFilePackagePath(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename());
}

export function getFilePackagePath(filePath) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/named.js
Expand Up @@ -43,7 +43,7 @@ module.exports = {
if (!deepLookup.found) {
if (deepLookup.path.length > 1) {
const deepPath = deepLookup.path
.map(i => path.relative(path.dirname((context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename()), i.path))
.map(i => path.relative(path.dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()), i.path))
.join(' -> ');

context.report(im[key],
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newline-after-import.js
Expand Up @@ -144,7 +144,7 @@ after ${type} statement not followed by another ${type}.`,
}
},
'Program:exit': function () {
log('exit processing for', (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename());
log('exit processing for', context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename());
const scopeBody = getScopeBody(context.getScope());
log('got scope:', scopeBody);

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-cycle.js
Expand Up @@ -37,7 +37,7 @@ module.exports = {
},

create: function (context) {
const myPath = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
if (myPath === '<text>') return {}; // can't cycle-check a non-file

const options = context.options[0] || {};
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-extraneous-dependencies.js
Expand Up @@ -69,7 +69,7 @@ function getDependencies(context, packageDir) {
Object.assign(
packageContent,
extractDepFields(
readPkgUp.sync({ cwd: (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename(), normalize: false }).pkg
readPkgUp.sync({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg
)
);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ module.exports = {

create: function (context) {
const options = context.options[0] || {};
const filename = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
const deps = getDependencies(context, options.packageDir) || extractDepFields({});

const depsOptions = {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-import-module-exports.js
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import pkgUp from 'pkg-up';

function getEntryPoint(context) {
const pkgPath = pkgUp.sync((context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename());
const pkgPath = pkgUp.sync(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename());
try {
return require.resolve(path.dirname(pkgPath));
} catch (error) {
Expand Down Expand Up @@ -39,7 +39,7 @@ module.exports = {
let alreadyReported = false;

function report(node) {
const fileName = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const fileName = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
const isEntryPoint = entryPoint === fileName;
const isIdentifier = node.object.type === 'Identifier';
const hasKeywords = (/^(module|exports)$/).test(node.object.name);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-relative-packages.js
Expand Up @@ -21,7 +21,7 @@ function checkImportForRelativePackage(context, importPath, node) {
}

const resolvedImport = resolve(importPath, context);
const resolvedContext = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const resolvedContext = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();

if (!resolvedImport || !resolvedContext) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-relative-parent-imports.js
Expand Up @@ -15,7 +15,7 @@ module.exports = {
},

create: function noRelativePackages(context) {
const myPath = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
if (myPath === '<text>') return {}; // can't check a non-file

function checkSourceValue(sourceNode) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-restricted-paths.js
Expand Up @@ -52,7 +52,7 @@ module.exports = {
const options = context.options[0] || {};
const restrictedPaths = options.zones || [];
const basePath = options.basePath || process.cwd();
const currentFilename = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const currentFilename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
const matchingZones = restrictedPaths.filter((zone) => {
const targetPath = path.resolve(basePath, zone.target);

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-self-import.js
Expand Up @@ -8,7 +8,7 @@ import moduleVisitor from 'eslint-module-utils/moduleVisitor';
import docsUrl from '../docsUrl';

function isImportingSelf(context, node, requireName) {
const filePath = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const filePath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();

// If the input is from stdin, this test can't fail
if (filePath !== '<text>' && filePath === resolve(requireName, context)) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unassigned-import.js
Expand Up @@ -32,7 +32,7 @@ function testIsAllow(globs, filename, source) {

function create(context) {
const options = context.options[0] || {};
const filename = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
const isAllow = source => testIsAllow(options.allow, filename, source);

return {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unused-modules.js
Expand Up @@ -463,7 +463,7 @@ module.exports = {
doPreparation(src, ignoreExports, context);
}

const file = (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename();
const file = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();

const checkExportPresence = node => {
if (!missingExports) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-useless-path-segments.js
Expand Up @@ -58,7 +58,7 @@ module.exports = {
},

create(context) {
const currentDir = path.dirname((context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename());
const currentDir = path.dirname(context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename());
const options = context.options[0];

function checkSourceValue(source) {
Expand Down
2 changes: 1 addition & 1 deletion utils/resolve.js
Expand Up @@ -218,7 +218,7 @@ const erroredContexts = new Set();
function resolve(p, context) {
try {
return relative( p
, (context.getPhysicalFilename && context.getPhysicalFilename()) || context.getFilename()
, context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename()
, context.settings
);
} catch (err) {
Expand Down

0 comments on commit 8c3aafa

Please sign in to comment.