Giter Club home page Giter Club logo

eslint-plugin-script-tags's Introduction

eslint-plugin-script-tags

Build Status

An ESLint plugin that allows you to lint the content of <script> tags in arbitrary text.

Unlike eslint-plugin-html, which parses HTML to find <script>s, this plugin uses a regular expression.

The advantage of using a regular expression, and the reason this plugin exists, is that by avoiding a parser you can find and lint <script>s in arbitrary text — text that might not parse nicely as HTML, such as Markdown files with HTML fenced code blocks that contain <script>s. Like this (imagine the '''s are backticks):

Here is some *markdown*.

'''html
<div>
<script>
  // Here is JS you'd like to lint!
  var a = "foo";
</script>
'''

(If you want to lint JS fenced code blocks, use eslint-plugin-markdown).

The disadvantage of using a regular expression, of course, is that it's not as robust as a real parser. If your <script> is within a comment, for example, it will still be linted: the regular expression doesn't know about the comment. You might like that, or you might not.

Usage

Use this module like any other ESLint plugin.

Unfortunately, we do need to provide a finite list of file extensions to check. Here's the current list:

  • .html
  • .md
  • .jsp
  • .tag
  • .hbs
  • .ejs
  • .php
  • .vue
  • .erb

There's no reason not to add more: so if you'd like another, please PR!

Caveats

Indentation

Expected indentation (if you use the indent rule) is determined by the first line of code. This can get hairy if you do something sloppy like:

<script>var a = 'foo';
  var b = 'bar';
</script>

So I wouldn't do that.

Arbitrary tags

Ideally this module could allow you to arbitrarily modify the expected tags regular expression, from <script>...</script> to something like {% highlight js %}...{% endhighlight %} or [javascript-block]...[end javascript-block], etc. However, to do so would require adding options, and it doesn't seem that ESLint's built options into the processor API. If you would like this feature and want to work on adding options, your help would be welcome.

eslint-plugin-script-tags's People

Contributors

bjornkri avatar davidtheclark avatar prazgaitis avatar trusktr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.