posthtml-hint icon indicating copy to clipboard operation
posthtml-hint copied to clipboard

[discuss] I am trying to add the path information of linted js files to the report

Open nicholaslee119 opened this issue 7 years ago • 10 comments

Just as the title, because now, the report of errors, for example

PostHTML HINT
-------------

✖ error [10:12]
Special characters must be escaped : [ > ].

✖ error [12:3]
Special characters must be escaped : [ < ].

✖ error [12:21]
Special characters must be escaped : [ < ].

✖ error [12:30]
Special characters must be escaped : [ > ].

✖ error [15:17]
Tag must be paired, no start tag: [ </h1> ]

⚠  5 Errors

there is no information about where they come from,

And I try to add the information to it, but, the information (the parameter, tree) passed by postHTML isn't enough.

It seems we should do something on postHTML to pass more information to plugins, isn't it?

PS, by the way, I fix some typo, to pass the test and building. https://github.com/posthtml/posthtml-hint/pull/2

nicholaslee119 avatar Mar 14 '17 05:03 nicholaslee119

Agreed tree.options.from could be used to get the path but the plugins needs to be updated and options.from must be set (Gulp, webpack) will do 'automatically'

michael-ciniawsky avatar Mar 14 '17 19:03 michael-ciniawsky

plugin.js

module.exports = function posthtmlPlugin (options) {
  options = Object.assign({}, options)

  return function (tree) {
     console.log(tree.options.from)
  }
}

Node API

posthtml([ require('posthtml-hint')() ]).process(html, { from: 'path/to/file.html' })...

michael-ciniawsky avatar Mar 14 '17 19:03 michael-ciniawsky

I just check the new version of posthtml-loader, It seems that you guys already add the path information to the parameter by the loader, great!! waiting for the release!

nicholaslee119 avatar Mar 15 '17 06:03 nicholaslee119

but, It seems that the plugins of posthtml have the dependency on webpack/gulp/...., isn't it, so without those builders, the ecosystem of posthtml will be weak, isn't it?

nicholaslee119 avatar Mar 15 '17 06:03 nicholaslee119

Yep gulp-posthtml, posthtml-loader and friends normally add this for you, they are using the Node API and have there own File I/O handling :stuck_out_tongue: the example above is the bare Node API uncommon to be used directly, despite you're a Plugin and/or Middleware Developer :)

michael-ciniawsky avatar Mar 15 '17 06:03 michael-ciniawsky

? Plugins only depend on posthtml, and posthtml depends on the library it is integrated to when it comes to File I/O (the library has it's own logic to handle it)

michael-ciniawsky avatar Mar 15 '17 06:03 michael-ciniawsky

If you use the posthtml Node API and plugin x and don't set e.g the { from: ''} parameter you're lost yes 😛 . But shouldn't be a real problem

michael-ciniawsky avatar Mar 15 '17 06:03 michael-ciniawsky

sure, it is no a real problem now, but if someday there are more requests just like { from: ''}.
more friendly handler will be necessary, I think. sorry, just a little over consideration

nicholaslee119 avatar Mar 15 '17 06:03 nicholaslee119

more friendly handler will be necessary, I think.

How ? 🙃

michael-ciniawsky avatar Mar 15 '17 06:03 michael-ciniawsky

If a developer wants to use options which depend on builder like { from: ''}, there is a friendly notice in debug-time for that?

nicholaslee119 avatar Mar 15 '17 06:03 nicholaslee119