3.1.0-rc.1 • Published 4 years ago
eslint-utils2 v3.1.0-rc.1
eslint-utils2
在 eslint-utils 基础上优化 ReferenceTracker ,以支持通配符,例如:
import { ReferenceTracker } from "eslint-utils";
export default {
meta: {},
create(context) {
return {
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope());
const traceMap = {
// Find `console.*` .
console: {
[ReferenceTracker.SingleLevelWildcard]: {
[ReferenceTracker.READ]: true,
},
},
// Find `Object.prototype.**.bind()` .
Object: {
prototype: {
[ReferenceTracker.MultiLevelWildcard]: {
bind: {
[ReferenceTracker.CALL]: true,
},
},
},
},
};
for (const { node, path } of tracker.iterateGlobalReferences(
traceMap
)) {
context.report({
node,
message: "disallow {{name}}.",
data: { name: path.join(".") },
});
}
},
};
},
};以下是 eslint-utils README 原文。
🏁 Goal
This package provides utility functions and classes for make ESLint custom rules.
For examples:
- getStaticValue evaluates static value on AST.
- ReferenceTracker checks the members of modules/globals as handling assignments and destructuring.
📖 Usage
See documentation.
📰 Changelog
See releases.
❤️ Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
Development Tools
npm testruns tests and measures coverage.npm run cleanremoves the coverage result ofnpm testcommand.npm run coverageshows the coverage result of the lastnpm testcommand.npm run lintruns ESLint.npm run watchruns tests on each file change.