eslint-plugin-factorial
Advanced tools
Comparing version 2.0.15 to 2.0.16
{ | ||
"name": "eslint-plugin-factorial", | ||
"version": "2.0.15", | ||
"version": "2.0.16", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -1,51 +0,4 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const yaml = require('yaml') | ||
const retrieveAllowedCollections = (fileName) => { | ||
const regex = /modules\/(?<module>[^\/]+)/ | ||
const matchFileName = fileName.match(regex) | ||
if (!matchFileName) return [] | ||
const { module: moduleFileName } = matchFileName.groups | ||
const packagePath = path.join(process.cwd(), 'src/modules', moduleFileName, 'package.yml') | ||
if (!fs.existsSync(packagePath)) { | ||
console.warn( | ||
`Unable to retrieve allowed collections because '${packagePath}' file doesn't exists.` | ||
) | ||
return [] | ||
} | ||
try { | ||
const { collections } = yaml.parse(fs.readFileSync(packagePath, 'utf8')) | ||
return collections ?? [] | ||
} catch (error) { | ||
console.error(error) | ||
console.warn( | ||
`Unable to retrieve allowed collections because '${packagePath}' file is not a valid YAML.` | ||
) | ||
return [] | ||
} | ||
} | ||
/** @type {import('eslint').Rule.RuleModule} */ | ||
module.exports = { | ||
create(context) { | ||
const fileName = context.getFilename() | ||
const allowedCollections = retrieveAllowedCollections(fileName) | ||
// console.log(`Allowed collections for file: ${fileName}`, allowedCollections) | ||
// NOTE: If user collection is allowed, then access collection is also | ||
// allowed because it is an alias. We are in the process of renaming the | ||
// uses collection to access collection. | ||
if (allowedCollections.includes('modules/core/store/collections/users')) { | ||
allowedCollections.push('modules/core/store/collections/accesses') | ||
} | ||
const reportWarning = (node) => { | ||
@@ -55,3 +8,3 @@ context.report({ | ||
message: | ||
'Try to use GraphQL instead of this mobx-rest collection', | ||
'mobx-rest is deprecated. Use GraphQL instead.', | ||
}) | ||
@@ -67,9 +20,7 @@ } | ||
const validSpecifier = node.specifiers.filter((specifier) => { | ||
return specifier.importKind === 'value' | ||
return specifier.parent.importKind === 'value' | ||
}).length > 0 | ||
if (validImport && validSource && validSpecifier) { | ||
if (!allowedCollections.includes(value)) { | ||
reportWarning(node) | ||
} | ||
reportWarning(node) | ||
} | ||
@@ -79,2 +30,2 @@ }, | ||
}, | ||
} | ||
} |
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
4
13643
341