Skip to content

Extension does not use custom lint plugin, specified in deno.json config, when formatting #1346

@Mqxx

Description

@Mqxx

Describe the bug
When saving a file and denoland.vscode-deno is used as a default formatter, I get incorrect formatted files. The documentation states that the extension uses the deno.json config file for formatting. The problem with that is, that it does not respect custom linter plugins and thus formats the files incorrectly. It looks like the extension does a deno fmt instead of a deno lint --fix.

To Reproduce

  1. Use this custom plugin (or any other plugin):
export default {
  name: 'colon-spacing',
  rules: {
    'after-function': {
      create(context): Deno.lint.LintVisitor {
        return {
          TSTypeAnnotation(node): void {
            if (node.parent.type === 'FunctionDeclaration') {
              const functionStart = node.parent.range[0];
              const sectionEnd = node.range[0];
              const index =
                context.sourceCode.getText(node.parent).substring(0, sectionEnd - functionStart).search(/\) *$/) + 1;
              const sectionStart = functionStart + index;

              if (index !== -1 && sectionEnd - sectionStart !== 1) {
                context.report({
                  message: `Wrong colon spacing.`,
                  range: [sectionStart - 1, sectionEnd + 1],
                  fix(fixer) {
                    return fixer.replaceTextRange([sectionStart, sectionEnd], ' ');
                  }
                });
              }
            }
          }
        };
      }
    }
  }
} satisfies Deno.lint.Plugin;
  1. Use the example code:
export function Foo(prop1: string, prop2: number) : string {
  return 'Hello World!';
}
  1. Saving the file, using denoland.vscode-deno as formatter will result in the following:
- export function Foo(prop1: string, prop2: number) : string {
+ export function Foo(prop1: string, prop2: number): string {
  return 'Hello World!';
}
  1. But formatting, using deno lint --fix results in:
- export function Foo(prop1: string, prop2: number) : string {
+ export function Foo(prop1: string, prop2: number) : string {
  return 'Hello World!';
}

Expected behavior

The VS-Code extension should respect the custom linter plugins, provided in the deno.json config.

Versions

  • vscode: 1.105.1
  • deno: 2.5.6
  • extension: v3.46.1

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