Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-atomic-design

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-atomic-design - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

CHANGELOG.md

34

lib/helpers.js

@@ -7,33 +7,2 @@ const path = require('path');

const createSameModuleValidator = (sourcePath, levelMap, isStrict) => {
const { name: sourceName, dir: sourceDir } = path.parse(sourcePath);
const { name: moduleName } = path.parse(sourceDir);
const isModule = !Object.prototype.hasOwnProperty.call(levelMap, moduleName);
if (!isModule) {
return {
isModule,
validator: targetPath => ({}),
};
}
const isRoot = sourceName === moduleName;
const validator = targetPath => {
const { name, dir } = path.parse(targetPath);
return {
sourceName,
moduleName,
isStrict,
isRoot,
isSameModule: dir === sourceDir,
isValidImport: name.startsWith(moduleName),
};
};
return {
isModule,
validator,
};
};
const levelStringRegex = new RegExp(

@@ -62,3 +31,3 @@ `([${Object.keys(OPTION_IDENTIFIERS)

const root = process.cwd();
return absolutePath => require('path').relative(root, absolutePath);
return absolutePath => path.relative(root, absolutePath);
})();

@@ -137,4 +106,3 @@

createDefaultLevelFinder,
createSameModuleValidator,
filterAllowedLevels,
};

@@ -18,3 +18,2 @@ /**

filterAllowedLevels,
createSameModuleValidator,
} = require('../helpers');

@@ -28,2 +27,4 @@

const validateModule = require('../validateModule');
const DEFAULT_LEVELS = [

@@ -112,8 +113,7 @@ 'atoms',

}
const allowedLevels = filterAllowedLevels(currentLevel, levelMap);
const { isModule, validator: moduleValidator } = !['off', false].includes(
options.module
)
? createSameModuleValidator(
const moduleValidator = !['off', false].includes(options.module)
? validateModule(
context,
currentPath,

@@ -123,3 +123,3 @@ levelMap,

)
: { isModule: false, validator: () => ({}) };
: () => {};

@@ -130,2 +130,3 @@ const validate = (sourcePath, node, importOrRequire) => {

}
const resolvedPath = require('eslint-module-utils/resolve').default(

@@ -135,2 +136,3 @@ sourcePath,

);
if (

@@ -143,2 +145,9 @@ !resolvedPath ||

if (
typeof moduleValidator(resolvedPath, node, importOrRequire) ===
'boolean'
) {
return;
}
const importLevel = findLevel(resolvedPath);

@@ -153,34 +162,7 @@ if (

if (isModule) {
const {
sourceName,
moduleName,
isStrict,
isRoot,
isSameModule,
isValidImport,
} = moduleValidator(resolvedPath);
if (isSameModule) {
if (isValidImport && (!isStrict || isRoot)) {
return;
}
return context.report({
node,
message: !isValidImport
? 'The child component name should start with {{moduleName}}.'
: 'In "strict" mode, Only the root module "{{moduleName}}" can use its children. "{{sourceName}}" is not root module. The children components cannot use each other.',
data: {
sourceName,
moduleName,
},
});
}
}
const tips = createTips(allowedLevels, importOrRequire);
context.report({
return context.report({
node,
message:
'Do not {{importOrRequire}} {{importLevel}} from {{currentLevel}}. {{currentLevelCapitilized}} {{tips}}.',
'Do not {{ importOrRequire }} {{ importLevel }} from {{ currentLevel }}. {{ currentLevelCapitilized }} {{ tips }}.',
data: {

@@ -187,0 +169,0 @@ importOrRequire,

{
"name": "eslint-plugin-atomic-design",
"version": "0.2.0",
"version": "0.2.1",
"description": "ESLint rules for Atomic Designed projects",

@@ -24,2 +24,3 @@ "keywords": [

"devDependencies": {
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/commit-analyzer": "^6.1.0",

@@ -65,2 +66,3 @@ "@semantic-release/github": "^5.2.10",

"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",

@@ -67,0 +69,0 @@ "@semantic-release/github"

@@ -69,3 +69,3 @@ # eslint-plugin-atomic-design

##### pathPatterns `Array<RegExpString>`
Patterns should contain a capturing group `(\\w+)`:
Patterns should contain a capturing group like `(\\w+)`:

@@ -82,2 +82,49 @@ ```javascript

##### module `'strict' | 'loose' | 'off' | false`
"module" mode allows to have children as module's "private" components.
in 'loose' mode (default setting):
```javascript
// in './components/molecules/SuperDatepicker/SuperDatepickerCalender.js'
// valid
import CommonLabel from '@/components/atom/CommonLabel.js';
import SuperDatepickerCalenderInput from '@/components/molecules/SuperDatepicker/SuperDatepickerCalenderInput.js';
// invalid (Module children are "private")
import OtherModuleChildren from '@/components/molecules/OtherModule/OtherModuleChildren.js';
```
in 'strict' mode, "private" children are protected even if importing comes from the same module siblings:
```javascript
// in './components/molecules/SuperDatepicker/SuperDatepickerCalender.js'
// valid
import CommonLabel from '@/components/atom/CommonLabel.js';
// invalid (Module children are "private")
import OtherModuleChildren from '@/components/molecules/OtherModule/OtherModuleChildren.js';
// invalid (Only the module root component can import its children)
import SuperDatepickerCalenderInput from '@/components/molecules/SuperDatepicker/SuperDatepickerCalenderInput.js';
// valid in the "root" component './components/molecules/SuperDatepicker/SuperDatepicker.js'
```
in non-module mode:
```javascript
// in './components/molecules/SuperDatepicker/SuperDatepickerCalender.js'
// valid
import CommonLabel from '@/components/atom/CommonLabel.js';
// invalid (molecules -> molecules)
import OtherModuleChildren from '@/components/molecules/OtherModule/OtherModuleChildren.js';
import SuperDatepickerCalenderInput from '@/components/molecules/SuperDatepicker/SuperDatepickerCalenderInput.js';
```
default: `loose`
© [RyoNkmr](https://github.com/RyoNkmr)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc