eslint-plugin-forum-react
Advanced tools
Comparing version
"use strict"; | ||
const path = require('path') | ||
const path = require('path'); | ||
module.exports = { | ||
@@ -8,3 +9,4 @@ meta: { | ||
docs: { | ||
description: "fsd relative path checker", | ||
description: "feature sliced relative path checker", | ||
category: "Fill me in", | ||
recommended: false, | ||
@@ -20,12 +22,11 @@ url: null, // URL to the documentation page for this rule | ||
ImportDeclaration(node) { | ||
// for example './ui/Article.tsx' | ||
// example app/entities/Article | ||
const importTo = node.source.value; | ||
// example D:\PROJECTS\Production-project\Forum-React\src\entities\index.ts | ||
// example C:\Users\tim\Desktop\javascript\production_project\src\entities\Article | ||
const fromFilename = context.getFilename(); | ||
if(shouldBeRelative(fromFilename, importTo)) { | ||
context.report(node, 'В рамках одного слайса все пути должны быть относительными!'); | ||
context.report(node, 'В рамках одного слайса все пути должны быть относительными'); | ||
} | ||
} | ||
@@ -43,15 +44,16 @@ }; | ||
'features': 'features', | ||
'shared': 'shared', | ||
'pages': 'pages', | ||
'widgets': 'widgets', | ||
'shared': 'shared', | ||
} | ||
function shouldBeRelative(from, to) { | ||
if (isPathRelative(to)){ | ||
if(isPathRelative(to)) { | ||
return false; | ||
} | ||
const toArray = to.split('./') | ||
const toLayer = toArray[0]; | ||
const toSlice = toArray[1]; | ||
// example entities/Article | ||
const toArray = to.split('/') | ||
const toLayer = toArray[0]; // entities | ||
const toSlice = toArray[1]; // Article | ||
@@ -65,2 +67,3 @@ if(!toLayer || !toSlice || !layers[toLayer]) { | ||
const fromArray = projectFrom.split('\\') | ||
const fromLayer = fromArray[1]; | ||
@@ -76,2 +79,9 @@ const fromSlice = fromArray[2]; | ||
console.log(path.toNamespacedPath()) | ||
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/Article/fasfasfas')) | ||
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'entities/ASdasd/fasfasfas')) | ||
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'features/Article/fasfasfas')) | ||
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\features\\Article', 'features/Article/fasfasfas')) | ||
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', 'app/index.tsx')) | ||
// console.log(shouldBeRelative('C:/Users/tim/Desktop/javascript/GOOD_COURSE_test/src/entities/Article', 'entities/Article/asfasf/asfasf')) | ||
// console.log(shouldBeRelative('C:\\Users\\tim\\Desktop\\javascript\\GOOD_COURSE_test\\src\\entities\\Article', '../../model/selectors/getSidebarItems')) | ||
{ | ||
"name": "eslint-plugin-forum-react", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "plugin for forum-react-project", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
7891
15.59%123
6.96%