Skip to content

VSCode - cannot get custom rule to run #11

@BVengo

Description

@BVengo

Hi there! We're having trouble getting a custom rule to run at all in our repo.

We want to enforce that trailing slashes are always used, which is the opposite behaviour from the built-in telescope rule path-no-trailing-slash. We wrote up a custom rule that mostly copies the code from the original rule but inverts the check.

import { defineRule } from "telescope-server";

export default defineRule({
	meta: {
		id: "must-have-trailing-slash",
		number: 9999,
		type: "suggestion",
		description: "Paths should end with trailing slashes",
		defaultSeverity: "warning"
	},
	check(ctx) {
		return {
			PathItem(pathItem) {
				const path = pathItem.path();
				if (!path) return;

				if (path === "/") return;

				if (!path.endsWith("/")) {  // The inverted line
					ctx.reportHere(pathItem, {
						message: `Path '${path}' should end with a trailing slash`,
						severity: "warning",
					});
				}
			},
		};
	},
});

In our config.yaml:

# `.telescope/config.yaml`
openapi:
  rulesOverrides: 
    path-no-trailing-slash: off
  rules:
    - rule: must-have-trailing-slash.ts

The rule override is working great, but the custom rule isn't triggering at all. I was wondering if we've done something incorrectly?

Cheers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions