zertosh / eslint-plugin-dependencies Goto Github PK
View Code? Open in Web Editor NEWrequire/import dependency validation
require/import dependency validation
Hi @zertosh ,
I'm using eslint-plugin-dependencies
with eslint-loader in a webpack configuration and i found a bug when i execute webpack --watch
.
Step to reproduce :
// my .eslintrc file
{
"extends": [
"standard"
],
"plugins": [
"dependencies"
],
"rules": {
"indent": [
"warn",
4
],
"dependencies/case-sensitive": 1,
"dependencies/no-cycles": 1,
"dependencies/no-unresolved": 0,
"dependencies/require-json-ext": 1
},
"globals" : {
"DEVELOPMENT": false,
"PRODUCTION": false,
"ENV": false
}
}
js/main.js
js/utils/a.js
js/utils/a.js
in js/main.js
// js/main.js
import a from './utils/a.js'
--watch
argumentjs/utils/b.js
js/utils/b.js
in js/main.js
// js/main.js
import a from './utils/a.js'
import b from './utils/b.js'
This should report dependencies/case-sensitive
error.
_readdirCache
is filled on first webpack run with something like:
_readdirCache['utils'] = [
'a.js'
]
and it's never updated.
This lines work :
// case-sensitive.js
// var _readdirCache = Object.create(null);
function readdirSync(dirname) {
// if (!(dirname in _readdirCache)) {
// try {
// _readdirCache[dirname] = fs.readdirSync(dirname);
// } catch (err) {
// _readdirCache[dirname] = null;
// }
// }
// return _readdirCache[dirname];
fs.readdirSync(dirname)
}
Is this project abandoned? There have been no commits since 2017. No feedback on PRs for some time. And it doesn't work with ESLint v6.
If there's anything that the community can help with, please let us know. Otherwise, should this project be forked?
I copied and pasted this from the docs:
"dependencies/no-cyles": [1, {"skip": ["/spec/", "/vendor/"], "types": true}]
which of course spews out:
warning Definition for rule 'dependencies/no-cyles' was not found dependencies/no-cyles
It should be dependencies/no-cycles
Would be awesome if this plugin can guard against (dis)allowed dependencies.
I'm having all my app modules in a directory called modules
, but to guard against circular references, I want to limit possible cross references between modules.
For example:
/src
/modules
/core
/layout
/lists
/tasks
/users
I don't want list
, tasks
, users
to be allowed to import anything from the layout
module, but layout
should be allowed to load components from lists
, tasks
and users
. I need this, because I use the index.js
in every module to expose a kind of public api.
I never import a nested file in another module. For example, lists/components/ListComponent
is not allowed to import Avatar from ../users/components/Avatar
, instead the import should be like import { Avatar } from '../users';
Hello.
You use commondir package in validation function. But it works wrong on Windows it replace slashes from windows style '' to UNIX '/', so validation turn to true all the time.
code from commondir packag>>
// Windows correctly handles paths with forward-slashes
return res.length > 1 ? res.join('/') : '/'
First of all, nice plugin! Especially love the automatic detection of cyclic dependencies. But...
Is this supposed to work on Windows? I have someone reporting that they got the following error: "Error: Failed to load plugin dependencies: Could not find eslint"
The RegExp at https://github.com/zertosh/eslint-plugin-dependencies/blob/master/no-cycles.js#L15 looks like it's not designed for Windows path delimiters.
I have the following .eslintrc.yml file, but it feels like a glob may be a bit easier.
plugins:
- dependencies
- react
rules:
"dependencies/case-sensitive": warn
"dependencies/no-cycles": warn
"dependencies/no-unresolved": [warn, {ignore: [chrome, sdk, sdk/request, sdk/timers, sdk/tabs, sdk/querystring, sdk/system, sdk/view/core, sdk/panel, sdk/simple-storage, sdk/self, sdk/page-mod, sdk/context-menu, sdk/system/events, sdk/frame/hidden-frame]}]
"dependencies/require-json-ext": warn
For dependencies/no-unresolved
, it'd be nice if I could do something like {ignore: [chrome, sdk, "sdk/*"]}
instead of specifying each dependency separately.
I got this warnings on 100% working codebase after porting it to typescript.
2:30 warning "./injectscript" does not exist dependencies/no-unresolved
3:27 warning "./isbrowser" does not exist dependencies/no-unresolved
Hi there!
I've got an issue with case sensitive test:
In my main file
import {
Home
} from './views' <- ESLint Warning dependencies/case-sensitive Case mismatch in "index"
In ./views/index.js
export Home from './home/Home'
Did I missed something ?
BTW I also tried in ./views/index.js
export {default as Home} from './home/Home'
Hi!
I was just looking for something like this! In my project, however, I'm setting the NODE_PATH
environment variable to find modules in our project, and it appears that node-resolve
doesn't respect NODE_PATH
. However, I was able to get things working by passing the paths
option to resolveOpts
, something like:
var resolveOpts = {
basedir: path.dirname(target),
extensions: ['.js', '.json', '.node'],
paths: [path.resolve(process.env.NODE_PATH)],
};
There's one obvious edge case here—if NODE_PATH
isn't set—and I suspect there may be more.
Is this something you'd consider adding to your plugin?
I have an error:
Failed to load plugin 'dependencies' declared in '.eslintrc.js': Cannot find module './util/traverser'
I maintain a similar plugin at https://github.com/benmosher/eslint-plugin-import.
Seems to do a lot of what you're doing with this. Just wanted to mention it. 😄
eslint-plugin-dependencies with ESLint v6 produce following error:
Error: Failed to load plugin 'dependencies' declared in '.eslintrc.js': Cannot find module './util/traverser'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at Object.<anonymous> (/Users/kato-kei/work/my-app/node_modules/eslint-plugin-dependencies/no-cycles.js:29:30)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
At ESLint v6, lib/util/traverser
was moved to lib/shared/traverser
.
https://github.com/eslint/eslint/blob/v5.16.0/lib/util/traverser.js
https://github.com/eslint/eslint/blob/v6.0.0/lib/shared/traverser.js
I tried to fix this path at local environment and work fine.
ERROR in ./src/index.js
Module build failed: Error: Cannot find module './util/traverser'
at Function.Module._resolveFilename (module.js:472:15)
at Function.Module._load (module.js:420:25)
at Module.require (module.js:500:17)
at Object. (/home/samuel/adam/adamui/client/node_modules/eslint-plugin-dependencies/no-cycles.js:24:30)
at Module._compile (module.js:573:32)
at Object.Module._extensions..js (module.js:582:10)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)
at Module.require (module.js:500:17)
at require (internal/module.js:20:19)
at Object. (/home/samuel/adam/adamui/client/node_modules/eslint-plugin-dependencies/index.js:6:18)
We use .jsx
for React components and we get errors when importing files that have .jsx
extension but without adding the extension in the import statement.
ex:
import x from './x';` // the file is x.jsx
Adding the extension to the import statement resolves the errors. Can this extension be added into https://github.com/zertosh/eslint-plugin-dependencies/blob/master/no-unresolved.js#L13, or a better solution would be to add an option for the extensions array to be overridden.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.