duhaime / eslint-plugin-frontmatter

Remove YAML frontmatter from `.js` files before calling ESLint
MIT License
0 stars 3 forks source link

Front Matter linter errors within .json files #10

Open ekfuhrmann opened 5 years ago

ekfuhrmann commented 5 years ago

When working within a .json file, I'm receiving linter errors for front matter.

image

.json File:

---
layout: null
---

{% assign isFirst = true %}
[
{%- for page in site.pages -%}
  {%- unless page.heading -%}{% continue %}{%- endunless -%}
  {%- unless isFirst -%},{%- endunless -%}
  {% assign isFirst = false %}
  {
    "heading"    : "{{ page.heading }}",
    "url"      : "{{ site.baseurl }}{{ page.url }}",
    "tags"     : "{{ page.tags | join: ', ' }}"
  }
{% endfor %}]

.eslintrc.json FIle:

{
  "extends": ["airbnb", "prettier"],
  "plugins": ["frontmatter", "prettier"],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2017,
    "sourceType": "module"
  },
  "globals": {},
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "rules": {
    "linebreak-style": 0
  }
}
duhaime commented 5 years ago

@ekfuhrmann thanks for your note, and sorry for your troubles.

I just pushed a branch and published a slight update (v0.0.8) so that this library will also strip frontmatter from JSON files.

I'm afraid that won't fully solve your problem, though, as even if you remove the frontmatter from the JSON file, the parser is going to blow up when it sees some of that Jekyll syntax in the body of the JSON file (e.g. {% assign cats = 'cats' %}, which is not valid JSON).

You could use an .eslintignore file that contains the path to your JSON file to ignore that file when processing your files with eslint, else I believe you'd want to find or write a plugin that handles Jekyll/Liquid templating in files.

That said, @platinumazure may have some better ideas...