1 | # stylelint-processor-arbitrary-tags
|
2 |
|
3 | [![Build Status](https://travis-ci.com/mapbox/stylelint-processor-arbitrary-tags.svg?branch=main)](https://travis-ci.com/mapbox/stylelint-processor-arbitrary-tags)
|
4 |
|
5 | A [stylelint processor](http://stylelint.io/user-guide/configuration/#processors) that allows you to lint CSS within arbitrary tags.
|
6 |
|
7 | The module uses a regular expression to identify code within the specified tags, then passes the code on to stylelint.
|
8 |
|
9 | By default, it looks for code within `<style>` tags (see default options below). But you can change the regular expression to find code within other tags, like `{% highlight css %}...{% endhighlight %}` for Jekyll templates, or `/* start css */.../* end css */` within a JS file, or who knows what else.
|
10 |
|
11 | ## Install
|
12 |
|
13 | ```
|
14 | npm install @mapbox/stylelint-processor-arbitrary-tags
|
15 | ```
|
16 |
|
17 | ## Options
|
18 |
|
19 | ### startTag
|
20 |
|
21 | Type: `string` that's RegExp-ready
|
22 |
|
23 | Default:
|
24 | ```
|
25 | '[^`\'"]<style[\\s\\S]*?>'
|
26 | ```
|
27 |
|
28 | ### endTag
|
29 |
|
30 | Type: `string` that's RegExp-ready
|
31 |
|
32 | Default:
|
33 | ```
|
34 | '</\\s*?style>'
|
35 | ```
|
36 |
|
37 | ### body
|
38 |
|
39 | Type: `string` that's RegExp-ready
|
40 |
|
41 | Default:
|
42 | ```
|
43 | '[\\s\\S]*?'
|
44 | ```
|
45 |
|
46 | ### fileFilterRegex
|
47 |
|
48 | Type: `array<RegExp|string>` that's an array of regular expressions or strings that describe files that you want to be processed with this module.
|
49 | Matches will be processed; files that do not match will not be.
|
50 |
|
51 | Given the following value, only `.html` files will be processed:
|
52 |
|
53 | ```js
|
54 | fileFilterRegex: [/\.html$/]
|
55 | ```
|
56 |
|
57 | You can also use regular expression strings instead of regular expression literals. This is necessary if you are using yaml-based configuration and can't use regular expression literals. Yaml variant of example above:
|
58 |
|
59 | ```yaml
|
60 | - fileFilterRegex:
|
61 | - '\.html$'
|
62 | ```
|
63 |
|
64 | This is useful when you want to create different settings for HTML and markdown, for instance.
|
65 |
|
66 | When empty (`[]`), every file will pass through the filter and be processed by this module.
|
67 |
|
68 | Default:
|
69 |
|
70 | ```js
|
71 | []
|
72 | ```
|
73 |
|
74 | ## Caveats
|
75 |
|
76 | **Do not use this processor with the `no-empty-source` rule**. If you do, you will have warnings whenever a file does not contain any matches for your regular expression.
|