Skip to content

Commit

Permalink
chore(lint): update to latest moving meadow config (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij authored Apr 11, 2020
1 parent 76c9093 commit 00121fe
Show file tree
Hide file tree
Showing 37 changed files with 92 additions and 68 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"files": ["test/**/*.js"],
"env": {
"mocha": true
},
"rules": {
"max-lines": "off",
"max-lines-per-function": "off"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion bin/depcruise-fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
// importing things only after the validateNodeEnv check so we can show an understandable
// error. Otherwise, on unsupported platforms we would show a stack trace, which is
// not so nice
/* eslint-disable global-require */
/* eslint-disable node/global-require */
const program = require("commander");
const $package = require("../package.json");
const format = require("../src/cli/format");
Expand Down
2 changes: 1 addition & 1 deletion bin/dependency-cruise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
// importing things only after the validateNodeEnv check so we can show an understandable
// error. Otherwise, on unsupported platforms we would show a stack trace, which is
// not so nice
/* eslint-disable global-require */
/* eslint-disable node/global-require */
const program = require("commander");
const $package = require("../package.json");
const cli = require("../src/cli");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"chai-json-schema": "1.5.1",
"coffeescript": "2.5.1",
"eslint": "6.8.0",
"eslint-config-moving-meadow": "1.2.0",
"eslint-config-moving-meadow": "1.3.0",
"eslint-config-prettier": "6.10.1",
"eslint-plugin-budapestian": "1.2.0",
"eslint-plugin-import": "2.20.2",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/compile-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function compileConfig(

let lReturnValue = readConfig(lResolvedFileName, pBaseDirectory);

if (lReturnValue.hasOwnProperty("extends")) {
if (Object.prototype.hasOwnProperty.call(lReturnValue, "extends")) {
lReturnValue = processExtends(
lReturnValue,
pAlreadyVisited,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/compile-config/read-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const stripJSONComments = require("strip-json-comments");

module.exports = pConfigFileName => {
if ([".js", ""].includes(path.extname(pConfigFileName))) {
/* eslint global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
/* eslint node/global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
return require(pConfigFileName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/get-resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = (pWebpackConfigFilename, pEnvironment, pArguments) => {
let lReturnValue = {};

try {
/* eslint global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
/* eslint node/global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
const lWebpackConfigModule = require(makeAbsolute(pWebpackConfigFilename));
const lWebpackConfig = pryConfigFromTheConfig(
lWebpackConfigModule,
Expand Down
4 changes: 3 additions & 1 deletion src/cli/init-config/normalize-init-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ module.exports = function normalizeInitOptions(pInitOptions) {
if (lReturnValue.useYarnPnP) {
lReturnValue.externalModuleResolutionStrategy = "yarn-pnp";
}
if (!lReturnValue.hasOwnProperty("hasTestsOutsideSource")) {
if (
!Object.prototype.hasOwnProperty.call(lReturnValue, "hasTestsOutsideSource")
) {
lReturnValue.hasTestsOutsideSource = !hasTestsWithinSource(
lReturnValue.testLocation,
lReturnValue.sourceLocation
Expand Down
13 changes: 8 additions & 5 deletions src/cli/normalize-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function ejectNonCLIOptions(pOptions) {
function normalizeConfigFile(pOptions, pConfigWrapperName, pDefault) {
let lOptions = _clone(pOptions);

if (lOptions.hasOwnProperty(pConfigWrapperName)) {
if (Object.prototype.hasOwnProperty.call(lOptions, pConfigWrapperName)) {
_set(
lOptions,
`ruleSet.options.${pConfigWrapperName}.fileName`,
Expand Down Expand Up @@ -148,17 +148,17 @@ module.exports = pOptionsAsPassedFromCommander => {
...ejectNonCLIOptions(pOptionsAsPassedFromCommander)
};

if (lOptions.hasOwnProperty("moduleSystems")) {
if (Object.prototype.hasOwnProperty.call(lOptions, "moduleSystems")) {
lOptions.moduleSystems = lOptions.moduleSystems
.split(",")
.map(pString => pString.trim());
}

if (lOptions.hasOwnProperty("config")) {
if (Object.prototype.hasOwnProperty.call(lOptions, "config")) {
lOptions.validate = lOptions.config;
}

if (lOptions.hasOwnProperty("validate")) {
if (Object.prototype.hasOwnProperty.call(lOptions, "validate")) {
lOptions.rulesFile = validateAndNormalizeRulesFileName(lOptions.validate);
lOptions.ruleSet = compileConfig(
path.isAbsolute(lOptions.rulesFile)
Expand All @@ -179,7 +179,10 @@ module.exports = pOptionsAsPassedFromCommander => {
defaults.TYPESCRIPT_CONFIG
);

lOptions.validate = lOptions.hasOwnProperty("validate");
lOptions.validate = Object.prototype.hasOwnProperty.call(
lOptions,
"validate"
);

return lOptions;
};
Expand Down
33 changes: 16 additions & 17 deletions src/extract/derive/reachable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const isReachable = require("./is-reachable");

function getReachableRules(pRuleSet) {
return _get(pRuleSet, "forbidden", [])
.filter(pRule => pRule.to.hasOwnProperty("reachable"))
.filter(pRule =>
Object.prototype.hasOwnProperty.call(pRule.to, "reachable")
)
.concat(
_get(pRuleSet, "allowed", []).filter(pRule =>
pRule.to.hasOwnProperty("reachable")
Object.prototype.hasOwnProperty.call(pRule.to, "reachable")
)
);
}
Expand Down Expand Up @@ -47,21 +49,18 @@ function mergeReachableProperties(pModule, pRule, pIsReachable) {
function addReachableToGraph(pGraph, pReachableRule) {
return pGraph.filter(onlyModulesInRuleFrom(pReachableRule)).reduce(
(pReturnGraph, pFromModule) =>
pReturnGraph.map(pToModule =>
Object.assign(
{},
pToModule,
isModuleInRuleTo(pReachableRule, pToModule)
? {
reachable: mergeReachableProperties(
pToModule,
pReachableRule,
isReachable(pGraph, pFromModule.source, pToModule.source)
)
}
: {}
)
),
pReturnGraph.map(pToModule => ({
...pToModule,
...(isModuleInRuleTo(pReachableRule, pToModule)
? {
reachable: mergeReachableProperties(
pToModule,
pReachableRule,
isReachable(pGraph, pFromModule.source, pToModule.source)
)
}
: {})
})),
_clone(pGraph)
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/extract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ function complete(pAll, pFromListItem) {

function makeOptionsPresentable(pOptions) {
return SHAREABLE_OPTIONS.filter(
pOption => pOptions.hasOwnProperty(pOption) && pOptions[pOption] !== 0
pOption =>
Object.prototype.hasOwnProperty.call(pOptions, pOption) &&
pOptions[pOption] !== 0
)
.filter(
pOption =>
Expand Down Expand Up @@ -185,7 +187,7 @@ function filterExcludedDependencies(pModule, pExclude) {
...pModule,
dependencies: pModule.dependencies.filter(
pDependency =>
!pExclude.hasOwnProperty("dynamic") ||
!Object.prototype.hasOwnProperty.call(pExclude, "dynamic") ||
pExclude.dynamic !== pDependency.dynamic
)
};
Expand Down
5 changes: 4 additions & 1 deletion src/extract/resolve/determine-dependency-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ function determineNpmDependencyTypes(pModuleName, pPackageDependencies) {
.filter(
pKey =>
pKey.includes("ependencies") &&
pPackageDependencies[pKey].hasOwnProperty(pModuleName)
Object.prototype.hasOwnProperty.call(
pPackageDependencies[pKey],
pModuleName
)
)
.map(pKey => NPM2DEP_TYPE[pKey] || "npm-no-pkg");
lReturnValue = lReturnValue.length === 0 ? ["npm-no-pkg"] : lReturnValue;
Expand Down
5 changes: 3 additions & 2 deletions src/extract/resolve/local-npm-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function dependencyIsDeprecated(pModule, pBaseDirectory, pResolveOptions) {

if (Boolean(lPackageJson)) {
lReturnValue =
lPackageJson.hasOwnProperty("deprecated") && lPackageJson.deprecated;
Object.prototype.hasOwnProperty.call(lPackageJson, "deprecated") &&
lPackageJson.deprecated;
}
return lReturnValue;
}
Expand All @@ -130,7 +131,7 @@ function getLicense(pModule, pBaseDirectory, pResolveOptions) {

if (
Boolean(lPackageJson) &&
lPackageJson.hasOwnProperty("license") &&
Object.prototype.hasOwnProperty.call(lPackageJson, "license") &&
typeof lPackageJson.license === "string"
) {
lReturnValue = lPackageJson.license;
Expand Down
4 changes: 2 additions & 2 deletions src/main/rule-set/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ function normalizeRule(pRule) {
* @return {object} [description]
*/
module.exports = pRuleSet => {
if (pRuleSet.hasOwnProperty("allowed")) {
if (Object.prototype.hasOwnProperty.call(pRuleSet, "allowed")) {
pRuleSet.allowedSeverity = normalizeSeverity(pRuleSet.allowedSeverity);
if (pRuleSet.allowedSeverity === "ignore") {
Reflect.deleteProperty(pRuleSet, "allowed");
Reflect.deleteProperty(pRuleSet, "allowedSeverity");
}
}

if (pRuleSet.hasOwnProperty("forbidden")) {
if (Object.prototype.hasOwnProperty.call(pRuleSet, "forbidden")) {
pRuleSet.forbidden = pRuleSet.forbidden
.map(normalizeRule)
.filter(pRule => pRule.severity !== "ignore");
Expand Down
6 changes: 3 additions & 3 deletions src/main/rule-set/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function validateAgainstSchema(pSchema, pConfiguration) {

function hasPath(pObject, pSection, pCondition) {
return (
pObject.hasOwnProperty(pSection) &&
pObject[pSection].hasOwnProperty(pCondition)
Object.prototype.hasOwnProperty.call(pObject, pSection) &&
Object.prototype.hasOwnProperty.call(pObject[pSection], pCondition)
);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ module.exports = pConfiguration => {
validateAgainstSchema(configurationSchema, pConfiguration);
(pConfiguration.allowed || []).forEach(checkRuleSafety);
(pConfiguration.forbidden || []).forEach(checkRuleSafety);
if (pConfiguration.hasOwnProperty("options")) {
if (Object.prototype.hasOwnProperty.call(pConfiguration, "options")) {
validateOptions(pConfiguration.options);
}
return pConfiguration;
Expand Down
14 changes: 6 additions & 8 deletions src/report/dot/module-utl.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ function smartURIConcat(pPrefix, pSource) {
}

function addURL(pPrefix) {
return pModule =>
Object.assign(
{},
pModule,
pModule.coreModule || pModule.couldNotResolve
? {}
: { URL: smartURIConcat(pPrefix, pModule.source) }
);
return pModule => ({
...pModule,
...(pModule.coreModule || pModule.couldNotResolve
? {}
: { URL: smartURIConcat(pPrefix, pModule.source) })
});
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion src/report/dot/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function matchesRE(pValue, pRE) {
function moduleMatchesCriteria(pSchemeEntry, pModule) {
return Object.keys(pSchemeEntry.criteria).every(
pKey =>
(_get(pModule, pKey) || pModule.hasOwnProperty(pKey)) &&
(_get(pModule, pKey) ||
Object.prototype.hasOwnProperty.call(pModule, pKey)) &&
(_get(pModule, pKey) === _get(pSchemeEntry.criteria, pKey) ||
matchesRE(_get(pModule, pKey), _get(pSchemeEntry.criteria, pKey)))
);
Expand Down
2 changes: 1 addition & 1 deletion src/report/error-html/utl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const version = require("../../../package.json").version;
function getFormattedAllowedRule(pRuleSetUsed) {
const lAllowed = _get(pRuleSetUsed, "allowed", []);
const lCommentedRule = lAllowed.find(pRule =>
pRule.hasOwnProperty("comment")
Object.prototype.hasOwnProperty.call(pRule, "comment")
);
const lComment = lCommentedRule ? lCommentedRule.comment : "-";

Expand Down
3 changes: 2 additions & 1 deletion src/validate/is-module-only-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/
function isModuleOnlyRule(pRule) {
return (
pRule.from.hasOwnProperty("orphan") || pRule.to.hasOwnProperty("reachable")
Object.prototype.hasOwnProperty.call(pRule.from, "orphan") ||
Object.prototype.hasOwnProperty.call(pRule.to, "reachable")
);
}

Expand Down
7 changes: 5 additions & 2 deletions src/validate/match-dependency-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function propertyEquals(pTo, pRule, pProperty) {
// ignore security/detect-object-injection because:
// - we only use it from within the module with two fixed values
// - the propertyEquals function is not exposed externaly
return pRule.to.hasOwnProperty(pProperty)
return Object.prototype.hasOwnProperty.call(pRule.to, pProperty)
? // eslint-disable-next-line security/detect-object-injection
pTo[pProperty] === pRule.to[pProperty]
: true;
Expand Down Expand Up @@ -44,7 +44,10 @@ function match(pFrom, pTo) {
matchers.toPath(pRule, pTo, lGroups) &&
matchers.toPathNot(pRule, pTo, lGroups) &&
matchers.toDependencyTypes(pRule, pTo) &&
(!pRule.to.hasOwnProperty("moreThanOneDependencyType") ||
(!Object.prototype.hasOwnProperty.call(
pRule.to,
"moreThanOneDependencyType"
) ||
pTo.dependencyTypes.length > 1) &&
matchers.toLicense(pRule, pTo) &&
matchers.toLicenseNot(pRule, pTo) &&
Expand Down
2 changes: 1 addition & 1 deletion test/cli/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function setModuleType(pTestPairs, pModuleType) {
cleanup: pTestPair.cleanup
};

lReturnValue.options = Object.assign({}, pTestPair.options);
lReturnValue.options = { ...pTestPair.options };
lReturnValue.options.outputTo = pTestPair.options.outputTo.replace(
/{{moduleType}}/g,
pModuleType
Expand Down
2 changes: 1 addition & 1 deletion test/cli/init-config/create-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ describe("cli/init-config/build-config", () => {
});

/* yep - doing some interesting things with requires here. Muffle eslint for this: */
/* eslint global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
/* eslint node/global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
2 changes: 1 addition & 1 deletion test/cli/init-config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ describe("cli/init-config/index", () => {
});
});
/* muffle eslint for we're doing the funky require shizzle consciously here */
/* eslint global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
/* eslint node/global-require:0, security/detect-non-literal-require:0, import/no-dynamic-require:0 */
2 changes: 1 addition & 1 deletion test/cli/init-config/write-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("cli/init-config/write-config", () => {
}`,
CUSTOM_CONFIG_FILE_NAME
);
// eslint-disable-next-line global-require,import/no-dynamic-require,security/detect-non-literal-require
// eslint-disable-next-line node/global-require,import/no-dynamic-require,security/detect-non-literal-require
const lResult = require(lConfigResultFileName);

expect(lResult).to.haveOwnProperty("aap");
Expand Down
1 change: 1 addition & 0 deletions test/extract/ast-extractors/extract-es6-deps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe("ast-extractors/extract-ES6-deps", () => {
let lDeps = [];

extractES6(
// eslint-disable-next-line no-template-curly-in-string
"import(`./dynamic/${enhop}`).then(pModule => pModule.x);",
lDeps
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe("ast-extractors/extract-typescript - regular commonjs require", () => {

it("ignores regular require with a template literal with placeholders", () => {
expect(
// eslint-disable-next-line no-template-curly-in-string
extractTypescript("const lala = require(`shwoooop/${blabla}`)")
).to.deep.equal([]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("ast-extractors/extract-typescript - dynamic imports", () => {
it("ignores dynamic import statements with a template that has placeholders", () => {
expect(
extractTypescript(
// eslint-disable-next-line no-template-curly-in-string
"import(`judeljo/${vlap}`).then(judeljo => { judeljo.hochik() }"
)
).to.deep.equal([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe("ast-extractors/extract-typescript - regular imports", () => {
it("leaves type imports with template literals with placeholders alone", () => {
expect(
// typescript/lib/protocol.d.ts has this thing
// eslint-disable-next-line no-template-curly-in-string
extractTypescript("const tiepetjes: import(`./types/${lalala()}`).T;")
).to.deep.equal([]);
});
Expand Down
2 changes: 1 addition & 1 deletion test/extract/index.cachebusting.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable global-require */
/* eslint-disable node/global-require */
const fs = require("fs");
const chai = require("chai");
const extract = require("../../src/extract");
Expand Down
Loading

0 comments on commit 00121fe

Please sign in to comment.