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

Comments

3 participants
@sugarshin
Copy link

sugarshin commented Feb 2, 2018

Hi,

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

@wooorm

This comment has been minimized.

Copy link
Member

wooorm commented Feb 2, 2018

Could you provide examples of ok and not ok input?

@sugarshin

This comment has been minimized.

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

This comment has been minimized.

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 Feb 3, 2018

@kachkaev

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

wooorm commented Feb 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment