@roq/eslint-plugin
Advanced tools
Comparing version 0.0.2 to 1.0.0
@@ -9,3 +9,2 @@ const path = require('path'); | ||
backend: ['decorators', 'dtos', 'entities', 'enums', 'guards', 'interfaces', 'loaders', 'mappers', 'models', 'repositories', 'resolvers', 'services', 'strategies', 'scalars', 'schemas'], | ||
backendModules: ['auth', 'config', 'event', 'library', 'platform', 'user'], | ||
frontend: ['components', 'configuration', 'layouts', 'pages', 'shared', 'slices', 'styles', 'utils', 'views'], | ||
@@ -12,0 +11,0 @@ frontendCommon: ['interfaces', 'roq-hooks', 'roq-ui'], |
@@ -1,3 +0,8 @@ | ||
const { escapedSep, resourceIdentifiers, allowedNamingPattern } = require('../constants'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { | ||
escapedSep, resourceIdentifiers, allowedNamingPattern, | ||
} = require('../constants'); | ||
const getPathPatterns = (backendBasePattern, frontendBasePattern, backendModuleList) => { | ||
@@ -21,2 +26,3 @@ const pathPatterns = { backend: {}, frontend: {} }; | ||
}; | ||
const get = (context) => { | ||
@@ -28,3 +34,3 @@ const pluginSettings = context.settings['roq-linter']; | ||
let frontendTestsPattern = ''; | ||
let backendModuleList = resourceIdentifiers.backendModules; | ||
const backendModuleList = []; | ||
@@ -34,24 +40,38 @@ if (pluginSettings) { | ||
backendBasePath, frontendBasePath, backendTestsBasePath, frontendTestsBasePath, | ||
backendModules, | ||
} = pluginSettings; | ||
if (backendBasePath) { | ||
if (typeof backendBasePath !== 'string' || !path.isAbsolute(`/${backendBasePath}`)) throw new Error('Invalid setting value for backendBasePath. Correct Example : "backend/src" '); | ||
backendBasePattern = `.*${escapedSep}${backendBasePath.replace(/\//g, escapedSep)}`; | ||
} | ||
if (frontendBasePath) { | ||
if (typeof frontendBasePath !== 'string' || !path.isAbsolute(`/${frontendBasePath}`)) throw new Error('Invalid setting value for frontendBasePath. Correct Example : "frontend/src" '); | ||
frontendBasePattern = `.*${escapedSep}${frontendBasePath.replace(/\//g, escapedSep)}`; | ||
} | ||
if (backendTestsBasePath) { | ||
if (typeof backendTestsBasePath !== 'string' || !path.isAbsolute(`/${backendTestsBasePath}`)) throw new Error('Invalid setting value for backendTestsBasePath. Correct Example : "backend/tests" '); | ||
backendTestsPattern = `.*${escapedSep}${backendTestsBasePath.replace(/\//g, escapedSep)}`; | ||
} | ||
if (frontendTestsBasePath) { | ||
if (typeof frontendTestsBasePath !== 'string' || !path.isAbsolute(`/${frontendTestsBasePath}`)) throw new Error('Invalid setting value for frontendTestsBasePath. Correct Example : "frontend/tests" '); | ||
frontendTestsPattern = `.*${escapedSep}${frontendTestsBasePath.replace(/\//g, escapedSep)}`; | ||
} | ||
if (backendModules) { | ||
if (Array.isArray(backendModules) && backendModules.every((e) => typeof e === 'string')) { | ||
backendModuleList = backendModules.map((e) => e.replace(/\//g, escapedSep)); | ||
} else { | ||
throw new Error('Invalid setting value for backendModule. Correct Example : ["auth", "nested/event"] '); | ||
} | ||
} | ||
const backendPath = backendBasePath || 'backend/src'; | ||
try { | ||
const [ backendPathInitToken ] = backendPath.split('/').filter(e=>e !== ''); | ||
const rootPath = path.resolve('./').replace(backendPathInitToken, ''); | ||
const dirContents = fs.readdirSync(path.resolve(rootPath, backendPath), { withFileTypes: true }); | ||
dirContents.forEach((e) => { | ||
if (e.isDirectory()) { | ||
const nestedDirContents = fs.readdirSync(path.resolve(rootPath, backendPath, e.name), | ||
{ withFileTypes: true }); | ||
if (nestedDirContents.some((el) => el.isFile())) { | ||
backendModuleList.push(e.name); | ||
} else { | ||
nestedDirContents.forEach(({ name: moduleName }) => { | ||
backendModuleList.push([e.name, moduleName].join(escapedSep)); | ||
}); | ||
} | ||
} | ||
}); | ||
} catch (_) { /* */ } | ||
const pathPatterns = getPathPatterns(backendBasePattern, frontendBasePattern, backendModuleList); | ||
@@ -67,3 +87,3 @@ return { | ||
} | ||
throw new Error('Add a "settings" object in eslint config file. With a nested object named "roq-linter", with allowed keys backendBasePath, frontendBasePath, backendTestsBasePath and frontendTestsBasePath which contain valid paths to the required resources. And also a list of "backendModules".'); | ||
throw new Error('Add a "settings" object in eslint config file. With a nested object named "roq-linter", with allowed keys backendBasePath, frontendBasePath, backendTestsBasePath and frontendTestsBasePath which contain valid paths to the required resources.'); | ||
}; | ||
@@ -70,0 +90,0 @@ |
@@ -55,4 +55,8 @@ const path = require('path'); | ||
const get = (context) => { | ||
const absoluteFilePath = context.getFilename(); | ||
let absoluteFilePath = context.getFilename(); | ||
if (sep !== '/' && absoluteFilePath.includes('/')) { | ||
absoluteFilePath = absoluteFilePath.replace(/\//g, '\\'); // for tests to be cross-platform compliant | ||
} | ||
const parentDir = { | ||
@@ -83,3 +87,3 @@ absolutePath: path.resolve(absoluteFilePath, '../'), | ||
const filePathParts = absoluteFilePath.split('/'); // as context object gives path in *nix-style across all platforms | ||
const filePathParts = absoluteFilePath.split(sep); | ||
const fileName = filePathParts[filePathParts.length - 1]; | ||
@@ -86,0 +90,0 @@ const fileTypeParts = fileName.split('.'); |
{ | ||
"name": "@roq/eslint-plugin", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -37,4 +37,2 @@ # roq-linter | ||
| ||
> - backendModules (default:["auth", "config", "event", "library", "platform", "user"]) => 'A list of relative paths (from backendBasePath) to backend modules' | ||
A sample settings object looks like => | ||
@@ -46,4 +44,3 @@ ```json | ||
"frontendBasePath": "frontend/src", | ||
"backendTestsBasePath": "backend/tests", | ||
"backendModules": ["auth", "config", "event", "library", "platform", "user", "nested/sample"] | ||
"backendTestsBasePath": "backend/tests" | ||
} | ||
@@ -50,0 +47,0 @@ } |
@@ -11,4 +11,4 @@ const { RuleTester } = require('eslint'); | ||
'roq-linter': { | ||
backendBasePath: 'tests/dummies/backend', | ||
frontendBasePath: 'tests/dummies/frontend', | ||
backendBasePath: 'roq-linter/tests/dummies/backend', | ||
frontendBasePath: 'roq-linter/tests/dummies/frontend', | ||
}, | ||
@@ -15,0 +15,0 @@ }, |
const { RuleTester } = require('eslint'); | ||
const { resolve } = require('path'); | ||
const ruleUnderTest = require('../../../lib/rules/filename-suffix-mismatch'); | ||
const testDummiesBasePath = resolve('./tests/dummies'); | ||
const ruleTesterInstance = new RuleTester({ | ||
@@ -8,4 +11,4 @@ parserOptions: { ecmaVersion: 2021 }, | ||
'roq-linter': { | ||
backendBasePath: 'backend/src', | ||
frontendBasePath: 'frontend/src', | ||
backendBasePath: 'roq-linter/tests/dummies/backend', | ||
frontendBasePath: 'roq-linter/tests/dummies/frontend', | ||
}, | ||
@@ -18,8 +21,9 @@ }, | ||
{ | ||
code: '// File Path : backend/src/auth/auth.module.ts', | ||
filename: 'backend/src/auth/auth.module.ts', | ||
code: '// File Path : tests/dummies/backend/auth/auth.module.ts', | ||
filename: resolve(testDummiesBasePath, 'backend/auth/auth.module.ts'), | ||
}, | ||
{ | ||
code: '// File Path : backend/src/auth/dto/auth-init-provider.dto.ts', | ||
filename: 'backend/src/auth/dto/auth-init-provider.dto.ts', | ||
code: '// File Path : tests/dummies/backend/auth/dtos/auth-init-provider.dto.ts', | ||
filename: resolve(testDummiesBasePath, 'backend/auth/dtos/auth-init-provider.dto.ts'), | ||
}, | ||
@@ -29,3 +33,3 @@ ], | ||
{ | ||
code: '// File Path: backend/src/auth/auth.ts', | ||
code: '// File Path: tests/dummies/backend/auth/auth.ts', | ||
errors: [{ | ||
@@ -39,6 +43,6 @@ messageId: 'exceptionalSuffixMismatch', | ||
], | ||
filename: 'backend/src/auth/auth.ts', | ||
filename: resolve(testDummiesBasePath, 'backend/auth/auth.ts'), | ||
}, | ||
{ | ||
code: '// File Path: backend/src/auth/dto/auth-init.provider.dto.ts', | ||
code: '// File Path: tests/dummies/backend/auth/dtos/auth-init.provider.dto.ts', | ||
errors: [{ | ||
@@ -51,5 +55,6 @@ messageId: 'regularSuffixMismatch', | ||
], | ||
filename: 'backend/src/auth/dto/auth-init.provider.dto.ts', | ||
filename: resolve(testDummiesBasePath, 'backend/auth/dtos/auth-init.provider.dto.ts'), | ||
}, | ||
], | ||
}); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
156638
92
4382
0
68
2