Skip to content

Commit dd4ee54

Browse files
cletuswRobinTail
andauthored
Add TS example to README
Fixes #19 Co-authored-by: RobinTail <robin_tail@me.com>
1 parent 2e0d84f commit dd4ee54

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Workaround for https://github.com/eslint/eslint/issues/8769 (previously https://
2222
npm install eslint-plugin-local-rules
2323
```
2424

25-
## Usage
25+
<h2 id="usage">Usage (JavaScript)</h3>
2626

2727
### ./eslint-local-rules.js (or ./eslint-local-rules/index.js)
2828

@@ -65,7 +65,55 @@ module.exports = {
6565
}
6666
```
6767

68-
### npm/yarn/pnpm workspaces support
68+
## Usage (TypeScript)
69+
70+
```
71+
npm install ts-node @types/eslint
72+
```
73+
74+
### ./eslint-local-rules/index.js
75+
76+
```javascript
77+
require("ts-node").register({
78+
transpileOnly: true,
79+
compilerOptions: {
80+
module: "commonjs",
81+
},
82+
});
83+
84+
module.exports = require("./rules").default;
85+
```
86+
87+
### ./eslint-local-rules/rules.ts
88+
89+
```typescript
90+
import type { Rule } from "eslint";
91+
92+
export default {
93+
"disallow-identifiers": {
94+
meta: {
95+
docs: {
96+
description: 'disallow identifiers',
97+
category: 'Possible Errors',
98+
recommended: false,
99+
},
100+
schema: [],
101+
},
102+
create: function (context) {
103+
return {
104+
Identifier: function (node) {
105+
context.report({
106+
node: node,
107+
message: 'Identifiers not allowed for Super Important reasons.',
108+
});
109+
},
110+
};
111+
},
112+
},
113+
} satisfies Record<string, Rule.RuleModule>;
114+
```
115+
116+
## npm/yarn/pnpm workspaces support
69117

70118
This plugin supports npm/yarn/pnpm workspaces, although note that if the eslint-local-rules.js file is in the workspace subdirectory, running from the project root is unsupported.
71119

0 commit comments

Comments
 (0)