Skip to content

Commit 0cd302e

Browse files
committed
refactor: rename blacklistAttributes to blocklistAttributes
1 parent 3d168d4 commit 0cd302e

File tree

7 files changed

+1068
-1068
lines changed

7 files changed

+1068
-1068
lines changed

README.md

+1,043-1,043
Large diffs are not rendered by default.

docs-src/md/introduction.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ You can run `npm run build` to compile them.
117117
| **utilities** | `{merge: _.mergeWith, template: _.template}` | Object of utilities methods to be passed to `<script props>`. By default lodash `mergeWith` and `template`. |
118118
| **elementAttributes** | `{}` | An object with tag name and a function modifier of valid-attributes.js. |
119119
| **safelistAttributes** | `['data-*']` | An array of attributes name to be added to default valid attributes. |
120-
| **blacklistAttributes** | `[]` | An array of attributes name to be removed from default valid attributes. |
120+
| **blocklistAttributes** | `[]` | An array of attributes name to be removed from default valid attributes. |
121121

122122
## Features
123123

@@ -793,7 +793,7 @@ const options = {
793793
],
794794

795795
// Remove attributes from all tags that support it
796-
blacklistAttributes: [
796+
blocklistAttributes: [
797797
'role'
798798
]
799799
}

docs/docs.html

+15-15
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ <h2 id="options" tabindex="-1">
643643
</tr>
644644
<tr>
645645
<td style="text-align:center">
646-
<strong>blacklistAttributes</strong>
646+
<strong>blocklistAttributes</strong>
647647
</td>
648648
<td style="text-align:center">
649649
<code>[]</code>
@@ -692,9 +692,9 @@ <h3 id="tag-names-and-x-tags" tabindex="-1">
692692
</p>
693693
<pre><code class="language-js">// index.js
694694

695-
const options = {
696-
root: './src',
697-
matcher: [{tag: 'a-tag'}, {tag: 'another-one'}, {tag: new RegExp(`^app-`, 'i')}]
695+
const options = {
696+
root: './src',
697+
matcher: [{tag: 'a-tag'}, {tag: 'another-one'}, {tag: new RegExp(`^app-`, 'i')}]
698698
};
699699

700700
require('posthtml')(require('posthtml-components')(options))
@@ -710,8 +710,8 @@ <h3 id="tag-names-and-x-tags" tabindex="-1">
710710
<p>Setup PostHTML:</p>
711711
<pre><code class="language-js">// index.js
712712

713-
const options = {
714-
root: './src',
713+
const options = {
714+
root: './src',
715715
tagPrefix: 'x-'
716716
};
717717

@@ -759,9 +759,9 @@ <h3 id="multiple-folders" tabindex="-1">
759759
You can set up the plugin like below:
760760
</p>
761761
<pre><code class="language-js">// index.js
762-
const options = {
763-
root: './src',
764-
folders: ['components', 'layouts']
762+
const options = {
763+
root: './src',
764+
folders: ['components', 'layouts']
765765
};
766766

767767
require('posthtml')(require('posthtml-components')(options))
@@ -991,7 +991,7 @@ <h3 id="stacks" tabindex="-1">
991991
&lt;fill:body&gt;Body content&lt;/fill:body&gt;
992992
&lt;fill:footer&gt;Footer content&lt;/fill:footer&gt;
993993
&lt;/x-modal&gt;
994-
994+
995995
&lt;stack name=&quot;scripts&quot;&gt;&lt;/stack&gt;
996996
&lt;/body&gt;
997997
&lt;/html&gt;</code></pre>
@@ -1132,8 +1132,8 @@ <h3 id="props" tabindex="-1">
11321132
<pre><code class="language-html">&lt;!-- src/modal.html --&gt;
11331133
&lt;script props&gt;
11341134
module.exports = {
1135-
title: props.title || 'Default title',
1136-
size: props.size ? `modal-${props.size}` : '',
1135+
title: props.title || 'Default title',
1136+
size: props.size ? `modal-${props.size}` : '',
11371137
items: Array.isArray(props.items) ? props.items.concat(['first', 'second']) : ['first', 'second']
11381138
}
11391139
&lt;/script&gt;
@@ -1335,7 +1335,7 @@ <h3 id="advanced-attributes-configurations" tabindex="-1">
13351335

13361336
const options = {
13371337
root: './src',
1338-
1338+
13391339
// Add attributes to specific tag or override defaults
13401340
elementAttributes: {
13411341
DIV: (defaultAttributes) =&gt; {
@@ -1351,15 +1351,15 @@ <h3 id="advanced-attributes-configurations" tabindex="-1">
13511351
return defaultAttributes;
13521352
},
13531353
},
1354-
1354+
13551355
// Add attributes to all tags, use '*' as wildcard for attribute name that starts with
13561356
safelistAttributes: [
13571357
'custom-attribute-name',
13581358
'attribute-name-start-with-*'
13591359
],
13601360

13611361
// Remove attributes from all tags that support it
1362-
blacklistAttributes: [
1362+
blocklistAttributes: [
13631363
'role'
13641364
]
13651365
}

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = (options = {}) => tree => {
8080
// { TAG: (attributes) => { attributes[] = 'attribute-name'; return attributes; } }
8181
options.elementAttributes = isPlainObject(options.elementAttributes) ? options.elementAttributes : {};
8282
options.safelistAttributes = Array.isArray(options.safelistAttributes) ? options.safelistAttributes : [];
83-
options.blacklistAttributes = Array.isArray(options.blacklistAttributes) ? options.blacklistAttributes : [];
83+
options.blocklistAttributes = Array.isArray(options.blocklistAttributes) ? options.blocklistAttributes : [];
8484

8585
// Merge customizer callback passed to lodash mergeWith
8686
// for merge attribute `props` and all attributes starting with `merge:`

src/process-attributes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ module.exports = (currentNode, attributes, props, options, aware) => {
4646

4747
const nodeAttrs = parseAttrs(mainNode.attrs, options.attrsParserRules);
4848

49-
// Merge elementAttributes and blacklistAttributes with options provided
50-
validAttributes.blacklistAttributes = union(validAttributes.blacklistAttributes, options.blacklistAttributes);
49+
// Merge elementAttributes and blocklistAttributes with options provided
50+
validAttributes.blocklistAttributes = union(validAttributes.blocklistAttributes, options.blocklistAttributes);
5151
validAttributes.safelistAttributes = union(validAttributes.safelistAttributes, options.safelistAttributes);
5252

5353
// Merge or override elementAttributes from options provided
@@ -64,7 +64,7 @@ module.exports = (currentNode, attributes, props, options, aware) => {
6464
}
6565

6666
// Attributes to be excluded
67-
const excludeAttributes = union(validAttributes.blacklistAttributes, keys(props), keys(aware), keys(options.props), ['$slots']);
67+
const excludeAttributes = union(validAttributes.blocklistAttributes, keys(props), keys(aware), keys(options.props), ['$slots']);
6868
// All valid HTML attributes for the main element
6969
const allValidElementAttributes = isString(mainNode.tag) && has(validAttributes.elementAttributes, mainNode.tag.toUpperCase()) ? validAttributes.elementAttributes[mainNode.tag.toUpperCase()] : [];
7070
// Valid HTML attributes without the excluded

src/valid-attributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3546,7 +3546,7 @@ module.exports = {
35463546
]
35473547
},
35483548

3549-
// Safelist and blacklist attributes will be applied to all tags
3549+
// Safelist and blocklist attributes will be applied to all tags
35503550

35513551
// Add additional attributes, use '*' in the end to check by startsWith
35523552
// Example: 'start-with-*'
@@ -3556,5 +3556,5 @@ module.exports = {
35563556
],
35573557

35583558
// Skip this attributes
3559-
blacklistAttributes: []
3559+
blocklistAttributes: []
35603560
};

test/test-attributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ test('Must work with tag without attributes', async () => {
100100
expect(html).toBe(expected);
101101
});
102102

103-
test('Must use safelist and blacklist', async () => {
103+
test('Must use safelist and blocklist', async () => {
104104
const actual = `<component src="components/override-attributes.html" tabindex="-1" title="My button" custom-attribute="A custom attribute">My button</component>`;
105105
const expected = `<button custom-attribute="A custom attribute">My button</button>`;
106106

107107
const html = await posthtml([plugin({
108108
root: './test/templates',
109109
tag: 'component',
110110
safelistAttributes: ['custom-attribute'],
111-
blacklistAttributes: ['role', 'tabindex']
111+
blocklistAttributes: ['role', 'tabindex']
112112
})]).process(actual).then(result => clean(result.html));
113113

114114
expect(html).toBe(expected);

0 commit comments

Comments
 (0)