eslint-plugin-factorial
Advanced tools
Comparing version 2.0.10 to 2.0.11
{ | ||
"name": "eslint-plugin-factorial", | ||
"version": "2.0.10", | ||
"version": "2.0.11", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -55,3 +55,3 @@ const path = require('path') | ||
message: | ||
'You are not allowed to use this collection in this module. Try to use GraphQL counterpart', | ||
'Try to use GraphQL instead of this mobx-rest collection', | ||
}) | ||
@@ -58,0 +58,0 @@ } |
@@ -0,3 +1,45 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const yaml = require('yaml') | ||
const exceptions = ['navigation.ts', 'sidebar.ts', 'events.ts'] | ||
const specialFile = (fileName) => { | ||
return exceptions.some((exception) => fileName.endsWith(exception)) | ||
} | ||
const formatFilename = (filename, removeExtension = false) => { | ||
let result = filename.replace(/^(.*)\/modules/, 'modules') | ||
if (!removeExtension) { | ||
return result | ||
} | ||
return result.replace(/(\..*)$/, '') | ||
} | ||
const declaredDepenency = (fileName, matchNode, package) => { | ||
if (!fs.existsSync(package)) { | ||
console.warn( | ||
`Unable to decide if this import in '${fileName}' is a valid dependency because '${package}' file doesn't exists.` | ||
) | ||
return true | ||
} | ||
try { | ||
const { dependencies = [] } = yaml.parse( | ||
fs.readFileSync(package, 'utf8') | ||
) | ||
return dependencies.includes(matchNode) | ||
} catch (error) { | ||
console.error(error) | ||
console.warn( | ||
`Unable to decide if this import in '${fileName}' is a valid dependency because '${package}' file is not a valid YAML.` | ||
) | ||
return true | ||
} | ||
} | ||
// @ts-check | ||
@@ -18,45 +60,62 @@ /** @type {import('eslint').Rule.RuleModule} */ | ||
const specialFile = (fileName) => { | ||
return exceptions.some((exception) => fileName.endsWith(exception)) | ||
// Invalid dependency: Design System must to have dependencies to other modules | ||
if (fileName.match(dsRegex) && matchNode) { | ||
context.report({ | ||
node, | ||
message: | ||
`Design System must not be coupled to application modules such as ${matchNode.groups.module}`, | ||
}) | ||
return | ||
} | ||
if (matchFileName && matchNode) { | ||
const { module: moduleFileName } = matchFileName.groups | ||
const { module: moduleNode } = matchNode.groups | ||
if (!matchFileName || !matchNode) return | ||
// Valid depedency, same module | ||
if (moduleFileName === moduleNode) return | ||
const { module: moduleFileName } = matchFileName.groups | ||
const { module: moduleNode } = matchNode.groups | ||
// Invalid dependency: Core must to have dependencies to other modules | ||
if (moduleFileName === 'core' && !specialFile(moduleNode)) { | ||
context.report({ | ||
node, | ||
message: | ||
'Core must not have dependencies to other modules', | ||
}) | ||
} | ||
// Valid dependency, same module | ||
if (moduleFileName === moduleNode) return | ||
// TODO: We need to check that special files don't import extra stuff from other modules | ||
// Valid dependency because is 'core' | ||
if (moduleNode === 'core') return | ||
if (moduleNode !== 'core') { | ||
// Invalid dependency: Module one is coupled to module two | ||
context.report({ | ||
node, | ||
message: | ||
`'${moduleFileName}' module is coupled to '${moduleNode}' module. This is not allowed` | ||
}) | ||
} | ||
} | ||
// Invalid dependency: Core must to have dependencies to other modules | ||
if (moduleFileName === 'core') { | ||
// Core can import special files because they will be bundled together | ||
if (specialFile(moduleNode)) return | ||
// Invalid dependency: Design System must to have dependencies to other modules | ||
if (fileName.match(dsRegex) && matchNode) { | ||
context.report({ | ||
node, | ||
message: | ||
`Design System must not be coupled to application modules such as ${matchNode.groups.module}`, | ||
'Core must not have dependencies to other modules', | ||
}) | ||
return | ||
} | ||
}, | ||
const package = path.join(process.cwd(), 'src/modules', moduleFileName, 'package.yml') | ||
// Check if is a declared dependency in the package.yml | ||
if (!declaredDepenency(fileName, matchNode, package)) { | ||
context.report({ | ||
node, | ||
message: `Avoid using elements from another module that are not declared as valid dependency. Review the list of 'dependencies' in file ${formatFilename( | ||
package | ||
)} and decide if '${moduleNode}' should be a dependency for this module.`, | ||
}) | ||
return | ||
} | ||
// Check that special files don't import extra stuff from other modules | ||
if (specialFile(fileName)) { | ||
context.report({ | ||
node, | ||
message: `Special files like (${exceptions.join(', ')} can not import elements from another module because they will be bundled in 'core' module` | ||
}) | ||
} | ||
} | ||
} | ||
}, | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14333
13
354