Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontmatter indent #169

Closed
sugarshin opened this issue Feb 2, 2018 · 5 comments
Closed

Frontmatter indent #169

sugarshin opened this issue Feb 2, 2018 · 5 comments
Labels
👀 no/external This makes more sense somewhere else 🙋 no/question This does not need any changes

Comments

@sugarshin
Copy link

Hi,

I need detect mixed indent with tab in Frontmatter. Is there a way?

@wooorm
Copy link
Member

wooorm commented Feb 2, 2018

Could you provide examples of ok and not ok input?

@sugarshin
Copy link
Author

sugarshin commented Feb 2, 2018

fail ❌

---
user:
  name: sugarshin
	url: github.com/sugarshin
---

ok ✅

---
user:
  name: sugarshin
  url: github.com/sugarshin
---

Do you understand?

@wooorm
Copy link
Member

wooorm commented Feb 3, 2018

This depends on what front matter you use. remark-frontmatter can help detect the front matter, but as so many different flavours exist (yaml, toml, and JSON), I don’t think the core of remark-lint should support this.

However, it is of course definitely possible to create external rules.

For example, to check if the YAML is valid, something like this may work (not tested):

var rule = require('unified-lint-rule');
var visit = require('unist-util-visit');
var generated = require('unist-util-generated');
var yaml = require('js-yaml');

module.exports = rule('remark-lint:yaml', yaml);

function yaml(ast, file) {
  visit(ast, 'yaml', visitor);

  function visitor(node) {
    if (!generated(node)) {
      try {
        yaml.safeLoad(node.value);
      } catch (err) {
        file.message(err, node)
      }
    }
  }
}

I’m closing this in favour of remarkjs/ideas#3. If someone would like to work on this, comment there!

@wooorm wooorm closed this as completed Feb 3, 2018
@kachkaev
Copy link

kachkaev commented Feb 3, 2018

Why does linter visit the yaml node that remark-frontmatter creates? Was not it supposed to be skipped?

@wooorm
Copy link
Member

wooorm commented Feb 3, 2018

In the above example, it is created by remark-frontmatter, and checked by the above code?

@wooorm wooorm added the 🙋 no/question This does not need any changes label Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 🙋 no/question This does not need any changes
Development

No branches or pull requests

3 participants