Skip to content

Support syntax-specific ESLint parsers for new unsaved buffers #323

@dndrsn

Description

@dndrsn

ESLint plugins like eslint-plugin-yaml often depend on file name matching to parse specific file types. For example...

  overrides: [
    {
      files: ["*.yaml", "*.yml"],
      parser: "yaml-eslint-parser",
    },
  ],

Linting a new, never saved buffer that requires a syntax-specific parser (after manually setting the buffer syntax) does not work properly. ESLint has no way to know the override parser:

New never saved buffer command:
cat <buffer 268> | /path/to/eslint --format json --stdin

Previously saved buffer command:
cat test.yml | /path/to/eslint --format json --stdin --stdin-filename /path/to/test.yml

Not sure if there is any (clean) way to support this. One possible solution would be to pass a dummy filename via --stdin-filename for the buffer based on the buffer's syntax type. That would probably require a map of selectors to dummy file names/extensions.

The primary use case I have for this is using a new buffer as a scratchpad. The workaround is to just save to a temporary file with the correct file extension, but that can be tedious. Hope that is somewhat clear. Thanks.

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