@adobe/remark-gridtables 3.0.4 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/eslint/index.js +124 -0
- package/eslint/plugins/header/comment-parser.cjs +24 -0
- package/eslint/plugins/header/header.cjs +272 -0
- package/eslint/plugins/header/index.cjs +10 -0
- package/eslint/rules/best-practices.js +424 -0
- package/eslint/rules/errors.js +189 -0
- package/eslint/rules/es6.js +199 -0
- package/eslint/rules/imports.js +283 -0
- package/eslint/rules/node.js +57 -0
- package/eslint/rules/strict.js +6 -0
- package/eslint/rules/style.js +534 -0
- package/eslint/rules/variables.js +57 -0
- package/eslint.config.js +22 -0
- package/package.json +7 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [3.0.5](https://github.com/adobe/remark-gridtables/compare/v3.0.4...v3.0.5) (2024-06-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @adobe/mdast-util-gridtables to v4.0.5 ([#100](https://github.com/adobe/remark-gridtables/issues/100)) ([8074e31](https://github.com/adobe/remark-gridtables/commit/8074e31c1b60cc48b58018ac332f9aca08f234af))
|
|
7
|
+
|
|
1
8
|
## [3.0.4](https://github.com/adobe/remark-gridtables/compare/v3.0.3...v3.0.4) (2024-04-02)
|
|
2
9
|
|
|
3
10
|
|
package/eslint/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import globals from 'globals';
|
|
13
|
+
import header from './plugins/header/index.cjs';
|
|
14
|
+
|
|
15
|
+
import bestPractices from './rules/best-practices.js';
|
|
16
|
+
import errors from './rules/errors.js';
|
|
17
|
+
import es6 from './rules/es6.js';
|
|
18
|
+
import node from './rules/node.js';
|
|
19
|
+
import strict from './rules/strict.js';
|
|
20
|
+
import style from './rules/style.js';
|
|
21
|
+
import variables from './rules/variables.js';
|
|
22
|
+
|
|
23
|
+
const common = {
|
|
24
|
+
languageOptions: {
|
|
25
|
+
ecmaVersion: 2022,
|
|
26
|
+
sourceType: 'module',
|
|
27
|
+
globals: {
|
|
28
|
+
...globals.node,
|
|
29
|
+
...globals.es6,
|
|
30
|
+
'__rootdir': true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
plugins: {
|
|
34
|
+
header,
|
|
35
|
+
},
|
|
36
|
+
rules: {
|
|
37
|
+
...bestPractices.rules,
|
|
38
|
+
...errors.rules,
|
|
39
|
+
...es6.rules,
|
|
40
|
+
...node.rules,
|
|
41
|
+
...strict.rules,
|
|
42
|
+
...style.rules,
|
|
43
|
+
...variables.rules,
|
|
44
|
+
|
|
45
|
+
strict: 0,
|
|
46
|
+
|
|
47
|
+
'import/prefer-default-export': 0,
|
|
48
|
+
|
|
49
|
+
// Forbid multiple statements in one line
|
|
50
|
+
'max-statements-per-line': ['error', { max: 1 }],
|
|
51
|
+
|
|
52
|
+
// Allow for-of loops
|
|
53
|
+
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
|
|
54
|
+
|
|
55
|
+
// Allow return before else & redundant else statements
|
|
56
|
+
'no-else-return': 'off',
|
|
57
|
+
|
|
58
|
+
// allow dangling underscores for 'fields'
|
|
59
|
+
'no-underscore-dangle': ['error', {
|
|
60
|
+
allowAfterThis: true,
|
|
61
|
+
}],
|
|
62
|
+
|
|
63
|
+
// allow '_' as a throw-away variable
|
|
64
|
+
'no-unused-vars': ['error', {
|
|
65
|
+
argsIgnorePattern: '^_$',
|
|
66
|
+
varsIgnorePattern: '^_$',
|
|
67
|
+
}],
|
|
68
|
+
|
|
69
|
+
'no-shadow': ['error', {
|
|
70
|
+
allow: ['_'],
|
|
71
|
+
}],
|
|
72
|
+
|
|
73
|
+
// don't enforce extension rules
|
|
74
|
+
// 'import/extensions': [2, 'ignorePackages'],
|
|
75
|
+
|
|
76
|
+
// enforce license header
|
|
77
|
+
'header/header': [2, 'block', ['',
|
|
78
|
+
{ pattern: ' * Copyright \\d{4} Adobe\\. All rights reserved\\.', template: ' * Copyright 2024 Adobe. All rights reserved.' },
|
|
79
|
+
' * This file is licensed to you under the Apache License, Version 2.0 (the "License");',
|
|
80
|
+
' * you may not use this file except in compliance with the License. You may obtain a copy',
|
|
81
|
+
' * of the License at http://www.apache.org/licenses/LICENSE-2.0',
|
|
82
|
+
' *',
|
|
83
|
+
' * Unless required by applicable law or agreed to in writing, software distributed under',
|
|
84
|
+
' * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS',
|
|
85
|
+
' * OF ANY KIND, either express or implied. See the License for the specific language',
|
|
86
|
+
' * governing permissions and limitations under the License.',
|
|
87
|
+
' ',
|
|
88
|
+
]],
|
|
89
|
+
|
|
90
|
+
'id-match': ['error', '^(?!.*?([wW][hH][iI][tT][eE]|[bB][lL][aA][cC][kK]).*[lL][iI][sS][tT]).*$', {
|
|
91
|
+
properties: true,
|
|
92
|
+
}],
|
|
93
|
+
},
|
|
94
|
+
files: ['*.js'],
|
|
95
|
+
linterOptions: {
|
|
96
|
+
reportUnusedDisableDirectives: 'off',
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const source = {
|
|
101
|
+
...common,
|
|
102
|
+
files: ['src/*.js', 'src/**/*.js', 'test/dev/*.mjs'],
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const test = {
|
|
106
|
+
...common,
|
|
107
|
+
languageOptions: {
|
|
108
|
+
globals: {
|
|
109
|
+
...common.languageOptions.globals,
|
|
110
|
+
...globals.mocha,
|
|
111
|
+
'__testdir': true,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
files: ['test/*.js', 'test/**/*.js'],
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export default [
|
|
118
|
+
{
|
|
119
|
+
...source,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
...test,
|
|
123
|
+
}
|
|
124
|
+
];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// This is a really simple and dumb parser, that looks just for a
|
|
4
|
+
// single kind of comment. It won't detect multiple block comments.
|
|
5
|
+
|
|
6
|
+
module.exports = function commentParser(text) {
|
|
7
|
+
text = text.trim();
|
|
8
|
+
|
|
9
|
+
if (text.substr(0, 2) === "//") {
|
|
10
|
+
return [
|
|
11
|
+
"line",
|
|
12
|
+
text.split(/\r?\n/).map(function(line) {
|
|
13
|
+
return line.substr(2);
|
|
14
|
+
})
|
|
15
|
+
];
|
|
16
|
+
} else if (
|
|
17
|
+
text.substr(0, 2) === "/*" &&
|
|
18
|
+
text.substr(-2) === "*/"
|
|
19
|
+
) {
|
|
20
|
+
return ["block", text.substring(2, text.length - 2)];
|
|
21
|
+
} else {
|
|
22
|
+
throw new Error("Could not parse comment file: the file must contain either just line comments (//) or a single block comment (/* ... */)");
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fs = require("fs");
|
|
4
|
+
var commentParser = require("./comment-parser.cjs");
|
|
5
|
+
var os = require("os");
|
|
6
|
+
|
|
7
|
+
function isPattern(object) {
|
|
8
|
+
return typeof object === "object" && Object.prototype.hasOwnProperty.call(object, "pattern");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function match(actual, expected) {
|
|
12
|
+
if (expected.test) {
|
|
13
|
+
return expected.test(actual);
|
|
14
|
+
} else {
|
|
15
|
+
return expected === actual;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function excludeShebangs(comments) {
|
|
20
|
+
return comments.filter(function(comment) {
|
|
21
|
+
return comment.type !== "Shebang";
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Returns either the first block comment or the first set of line comments that
|
|
26
|
+
// are ONLY separated by a single newline. Note that this does not actually
|
|
27
|
+
// check if they are at the start of the file since that is already checked by
|
|
28
|
+
// hasHeader().
|
|
29
|
+
function getLeadingComments(context, node) {
|
|
30
|
+
var all = excludeShebangs(context.getSourceCode().getAllComments(node.body.length ? node.body[0] : node));
|
|
31
|
+
if (all[0].type.toLowerCase() === "block") {
|
|
32
|
+
return [all[0]];
|
|
33
|
+
}
|
|
34
|
+
for (var i = 1; i < all.length; ++i) {
|
|
35
|
+
var txt = context.getSourceCode().getText().slice(all[i - 1].range[1], all[i].range[0]);
|
|
36
|
+
if (!txt.match(/^(\r\n|\r|\n)$/)) {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return all.slice(0, i);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function genCommentBody(commentType, textArray, eol, numNewlines) {
|
|
44
|
+
var eols = eol.repeat(numNewlines);
|
|
45
|
+
if (commentType === "block") {
|
|
46
|
+
return "/*" + textArray.join(eol) + "*/" + eols;
|
|
47
|
+
} else {
|
|
48
|
+
return "//" + textArray.join(eol + "//") + eols;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function genCommentsRange(context, comments, eol) {
|
|
53
|
+
var start = comments[0].range[0];
|
|
54
|
+
var end = comments.slice(-1)[0].range[1];
|
|
55
|
+
if (context.getSourceCode().text[end] === eol) {
|
|
56
|
+
end += eol.length;
|
|
57
|
+
}
|
|
58
|
+
return [start, end];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function genPrependFixer(commentType, node, headerLines, eol, numNewlines) {
|
|
62
|
+
return function(fixer) {
|
|
63
|
+
return fixer.insertTextBefore(
|
|
64
|
+
node,
|
|
65
|
+
genCommentBody(commentType, headerLines, eol, numNewlines)
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function genReplaceFixer(commentType, context, leadingComments, headerLines, eol, numNewlines) {
|
|
71
|
+
return function(fixer) {
|
|
72
|
+
return fixer.replaceTextRange(
|
|
73
|
+
genCommentsRange(context, leadingComments, eol),
|
|
74
|
+
genCommentBody(commentType, headerLines, eol, numNewlines)
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function findSettings(options) {
|
|
80
|
+
var lastOption = options.length > 0 ? options[options.length - 1] : null;
|
|
81
|
+
if (typeof lastOption === "object" && !Array.isArray(lastOption) && lastOption !== null
|
|
82
|
+
&& !Object.prototype.hasOwnProperty.call(lastOption, "pattern")) {
|
|
83
|
+
return lastOption;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function getEOL(options) {
|
|
89
|
+
var settings = findSettings(options);
|
|
90
|
+
if (settings && settings.lineEndings === "unix") {
|
|
91
|
+
return "\n";
|
|
92
|
+
}
|
|
93
|
+
if (settings && settings.lineEndings === "windows") {
|
|
94
|
+
return "\r\n";
|
|
95
|
+
}
|
|
96
|
+
return os.EOL;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function hasHeader(src) {
|
|
100
|
+
if (src.substr(0, 2) === "#!") {
|
|
101
|
+
var m = src.match(/(\r\n|\r|\n)/);
|
|
102
|
+
if (m) {
|
|
103
|
+
src = src.slice(m.index + m[0].length);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return src.substr(0, 2) === "/*" || src.substr(0, 2) === "//";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function matchesLineEndings(src, num) {
|
|
110
|
+
for (var j = 0; j < num; ++j) {
|
|
111
|
+
var m = src.match(/^(\r\n|\r|\n)/);
|
|
112
|
+
if (m) {
|
|
113
|
+
src = src.slice(m.index + m[0].length);
|
|
114
|
+
} else {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = {
|
|
122
|
+
meta: {
|
|
123
|
+
type: "layout",
|
|
124
|
+
fixable: "whitespace",
|
|
125
|
+
schema: [
|
|
126
|
+
{
|
|
127
|
+
enum: ["block", "line"]
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
type: "array",
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
create: function(context) {
|
|
135
|
+
var options = context.options;
|
|
136
|
+
var numNewlines = options.length > 2 ? options[2] : 1;
|
|
137
|
+
var eol = getEOL(options);
|
|
138
|
+
|
|
139
|
+
// If just one option then read comment from file
|
|
140
|
+
if (options.length === 1 || (options.length === 2 && findSettings(options))) {
|
|
141
|
+
var text = fs.readFileSync(context.options[0], "utf8");
|
|
142
|
+
options = commentParser(text);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
var commentType = options[0].toLowerCase();
|
|
146
|
+
var headerLines, fixLines = [];
|
|
147
|
+
// If any of the lines are regular expressions, then we can't
|
|
148
|
+
// automatically fix them. We set this to true below once we
|
|
149
|
+
// ensure none of the lines are of type RegExp
|
|
150
|
+
var canFix = false;
|
|
151
|
+
if (Array.isArray(options[1])) {
|
|
152
|
+
canFix = true;
|
|
153
|
+
headerLines = options[1].map(function(line) {
|
|
154
|
+
var isRegex = isPattern(line);
|
|
155
|
+
// Can only fix regex option if a template is also provided
|
|
156
|
+
if (isRegex && !line.template) {
|
|
157
|
+
canFix = false;
|
|
158
|
+
}
|
|
159
|
+
fixLines.push(line.template || line);
|
|
160
|
+
return isRegex ? new RegExp(line.pattern) : line;
|
|
161
|
+
});
|
|
162
|
+
} else if (isPattern(options[1])) {
|
|
163
|
+
var line = options[1];
|
|
164
|
+
headerLines = [new RegExp(line.pattern)];
|
|
165
|
+
fixLines.push(line.template || line);
|
|
166
|
+
// Same as above for regex and template
|
|
167
|
+
canFix = !!line.template;
|
|
168
|
+
} else {
|
|
169
|
+
canFix = true;
|
|
170
|
+
headerLines = options[1].split(/\r?\n/);
|
|
171
|
+
fixLines = headerLines;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
Program: function(node) {
|
|
176
|
+
if (!hasHeader(context.getSourceCode().getText())) {
|
|
177
|
+
context.report({
|
|
178
|
+
loc: node.loc,
|
|
179
|
+
message: "missing header",
|
|
180
|
+
fix: genPrependFixer(commentType, node, fixLines, eol, numNewlines)
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
var leadingComments = getLeadingComments(context, node);
|
|
184
|
+
|
|
185
|
+
if (!leadingComments.length) {
|
|
186
|
+
context.report({
|
|
187
|
+
loc: node.loc,
|
|
188
|
+
message: "missing header",
|
|
189
|
+
fix: canFix ? genPrependFixer(commentType, node, fixLines, eol, numNewlines) : null
|
|
190
|
+
});
|
|
191
|
+
} else if (leadingComments[0].type.toLowerCase() !== commentType) {
|
|
192
|
+
context.report({
|
|
193
|
+
loc: node.loc,
|
|
194
|
+
message: "header should be a {{commentType}} comment",
|
|
195
|
+
data: {
|
|
196
|
+
commentType: commentType
|
|
197
|
+
},
|
|
198
|
+
fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
if (commentType === "line") {
|
|
202
|
+
if (leadingComments.length < headerLines.length) {
|
|
203
|
+
context.report({
|
|
204
|
+
loc: node.loc,
|
|
205
|
+
message: "incorrect header",
|
|
206
|
+
fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
for (var i = 0; i < headerLines.length; i++) {
|
|
211
|
+
if (!match(leadingComments[i].value, headerLines[i])) {
|
|
212
|
+
context.report({
|
|
213
|
+
loc: node.loc,
|
|
214
|
+
message: "incorrect header",
|
|
215
|
+
fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
|
|
216
|
+
});
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var postLineHeader = context.getSourceCode().text.substr(leadingComments[headerLines.length - 1].range[1], numNewlines * 2);
|
|
222
|
+
if (!matchesLineEndings(postLineHeader, numNewlines)) {
|
|
223
|
+
context.report({
|
|
224
|
+
loc: node.loc,
|
|
225
|
+
message: "no newline after header",
|
|
226
|
+
fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
} else {
|
|
231
|
+
// if block comment pattern has more than 1 line, we also split the comment
|
|
232
|
+
var leadingLines = [leadingComments[0].value];
|
|
233
|
+
if (headerLines.length > 1) {
|
|
234
|
+
leadingLines = leadingComments[0].value.split(/\r?\n/);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
var hasError = false;
|
|
238
|
+
if (leadingLines.length > headerLines.length) {
|
|
239
|
+
hasError = true;
|
|
240
|
+
}
|
|
241
|
+
for (i = 0; !hasError && i < headerLines.length; i++) {
|
|
242
|
+
if (!match(leadingLines[i], headerLines[i])) {
|
|
243
|
+
hasError = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (hasError) {
|
|
248
|
+
if (canFix && headerLines.length > 1) {
|
|
249
|
+
fixLines = [fixLines.join(eol)];
|
|
250
|
+
}
|
|
251
|
+
context.report({
|
|
252
|
+
loc: node.loc,
|
|
253
|
+
message: "incorrect header",
|
|
254
|
+
fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
|
|
255
|
+
});
|
|
256
|
+
} else {
|
|
257
|
+
var postBlockHeader = context.getSourceCode().text.substr(leadingComments[0].range[1], numNewlines * 2);
|
|
258
|
+
if (!matchesLineEndings(postBlockHeader, numNewlines)) {
|
|
259
|
+
context.report({
|
|
260
|
+
loc: node.loc,
|
|
261
|
+
message: "no newline after header",
|
|
262
|
+
fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
};
|