@eslint-react/eslint 5.28.7 → 5.28.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,16 @@ export type RuleFeature = "CFG" | "DBG" | "FIX" | "MOD" | "TSC" | "EXP";
|
|
|
38
38
|
export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener> & {
|
|
39
39
|
name: string;
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Gets the source text of the given node or token.
|
|
43
|
+
* Can be used as `(context, node)` to get the text directly,
|
|
44
|
+
* or as `(context)` to get a `(node) => string` function (ex: for use in array callbacks).
|
|
45
|
+
* @param context The ESLint rule context.
|
|
46
|
+
* @param node The node or token to get the text of.
|
|
47
|
+
* @returns The source text of the node, or a function that returns it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getText(context: RuleContext, node: TSESTree.Node | TSESTree.Token): string;
|
|
50
|
+
export declare function getText(context: RuleContext): (node: TSESTree.Node | TSESTree.Token) => string;
|
|
41
51
|
/**
|
|
42
52
|
* Creates a report function for the given rule context.
|
|
43
53
|
* @param context The ESLint rule context.
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,10 @@ function getDocsUrl(ruleName) {
|
|
|
10
10
|
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
11
11
|
}
|
|
12
12
|
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
13
|
+
function getText(context, ...rest) {
|
|
14
|
+
if (rest.length === 1) return context.sourceCode.getText(rest[0]);
|
|
15
|
+
return (node) => context.sourceCode.getText(node);
|
|
16
|
+
}
|
|
13
17
|
function report(context) {
|
|
14
18
|
return (desc) => {
|
|
15
19
|
if (desc == null) return;
|
|
@@ -27,4 +31,4 @@ function merge(base, ...rest) {
|
|
|
27
31
|
return base;
|
|
28
32
|
}
|
|
29
33
|
//#endregion
|
|
30
|
-
export { createRule, getConstrainedTypeAtLocation, merge, report };
|
|
34
|
+
export { createRule, getConstrainedTypeAtLocation, getText, merge, report };
|