mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
9de9385fd1
Part of #18610. Our intent is to move `definePlugin`, `defineRule`, and `eslintCompatPlugin` to a separate package `@oxlint/plugins` (plural to avoid confusion with naming convention for plugins `oxlint-plugin-xxx`). So rename the current entry point which exports these functions from `oxlint/plugin` to `oxlint/plugins` (plural).
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import type { Plugin } from "#oxlint/plugins";
|
|
|
|
const plugin: Plugin = {
|
|
meta: {
|
|
name: "interpolation-test",
|
|
},
|
|
rules: {
|
|
"no-var": {
|
|
create(context) {
|
|
return {
|
|
VariableDeclaration(node) {
|
|
if (node.kind === "var") {
|
|
const { declarations } = node;
|
|
if (declarations.length > 0) {
|
|
const firstDeclaration = declarations[0];
|
|
if (firstDeclaration.id.type === "Identifier") {
|
|
const { name } = firstDeclaration.id;
|
|
|
|
if (name === "testWithNoData") {
|
|
// Test with no placeholders, no data
|
|
context.report({
|
|
message: "Variables should not use var",
|
|
node,
|
|
});
|
|
} else if (name === "testWithName") {
|
|
// Test with single placeholder
|
|
context.report({
|
|
message: "Variable `{{name}}` should not use var",
|
|
node,
|
|
data: { name },
|
|
});
|
|
} else if (name === "testWithNameNoData") {
|
|
// Test with single placeholder, but no data
|
|
context.report({
|
|
message: "Variable `{{name}}` should not use var",
|
|
node,
|
|
});
|
|
} else if (name === "testWithMultiple") {
|
|
// Test with multiple placeholders
|
|
context.report({
|
|
message: "Variable `{{name}}` of type `{{type}}` should not use var",
|
|
node,
|
|
data: {
|
|
name,
|
|
type: "string",
|
|
},
|
|
});
|
|
} else if (name === "testWithMultipleNoData") {
|
|
// Test with multiple placeholders, but no data
|
|
context.report({
|
|
message: "Variable `{{name}}` of type `{{type}}` should not use var",
|
|
node,
|
|
});
|
|
} else if (name === "testWithMissingData") {
|
|
// Test missing data - placeholder should remain
|
|
context.report({
|
|
message: "Value is `{{value}}` and name is `{{name}}`",
|
|
node,
|
|
data: {
|
|
value: "example",
|
|
// name is missing
|
|
},
|
|
});
|
|
} else if (name === "testWithSpaces") {
|
|
// Test whitespace in placeholders
|
|
context.report({
|
|
message: "Value with spaces is `{{ value }}` and name is `{{ name }}`",
|
|
node,
|
|
data: {
|
|
value: "hello",
|
|
name: "world",
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
};
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export default plugin;
|