eslint-plugin-yenz 2.2.0-beta.1 → 2.2.0-beta.2
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.
|
@@ -149,6 +149,49 @@ function formatMergedSpecifierExport(items) {
|
|
|
149
149
|
.join(', ')} }`;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Returns a location that covers only the exported header (for example
|
|
154
|
+
* `export function foo()` through the closing `)`), not the whole declaration
|
|
155
|
+
* body, so editors underline the signature instead of the entire block.
|
|
156
|
+
*
|
|
157
|
+
* @param {object} exportNamedNode - Inline `ExportNamedDeclaration`.
|
|
158
|
+
* @param {import('eslint').SourceCode} sourceCode
|
|
159
|
+
* @returns {object} ESLint `SourceLocation` (`start` / `end` in line/column).
|
|
160
|
+
*/
|
|
161
|
+
function getInlineExportReportLoc(exportNamedNode, sourceCode) {
|
|
162
|
+
const declaration = exportNamedNode.declaration;
|
|
163
|
+
const { start } = exportNamedNode.loc;
|
|
164
|
+
|
|
165
|
+
const endsBeforeBraceBody =
|
|
166
|
+
(declaration.type === 'FunctionDeclaration'
|
|
167
|
+
|| declaration.type === 'ClassDeclaration'
|
|
168
|
+
|| declaration.type === 'TSInterfaceDeclaration')
|
|
169
|
+
&& declaration.body;
|
|
170
|
+
|
|
171
|
+
if (endsBeforeBraceBody) {
|
|
172
|
+
const bodyOpenIndex = declaration.body.range[0];
|
|
173
|
+
return {
|
|
174
|
+
start,
|
|
175
|
+
end: sourceCode.getLocFromIndex(bodyOpenIndex),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (declaration.type === 'TSTypeAliasDeclaration') {
|
|
180
|
+
const anchor = declaration.typeParameters ?? declaration.id;
|
|
181
|
+
const equalsToken = sourceCode.getTokenAfter(anchor, {
|
|
182
|
+
filter: (token) => token.type === 'Punctuator' && token.value === '=',
|
|
183
|
+
});
|
|
184
|
+
if (equalsToken) {
|
|
185
|
+
return {
|
|
186
|
+
start,
|
|
187
|
+
end: sourceCode.getLocFromIndex(equalsToken.range[0]),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return exportNamedNode.loc;
|
|
193
|
+
}
|
|
194
|
+
|
|
152
195
|
const exportAtEndOfFileRule = {
|
|
153
196
|
meta: {
|
|
154
197
|
type: 'suggestion',
|
|
@@ -180,7 +223,7 @@ const exportAtEndOfFileRule = {
|
|
|
180
223
|
|
|
181
224
|
violations.forEach((node) => {
|
|
182
225
|
context.report({
|
|
183
|
-
node,
|
|
226
|
+
loc: getInlineExportReportLoc(node, sourceCode),
|
|
184
227
|
message:
|
|
185
228
|
'Declare this without inline export and list it in a single export statement at the end of the file.',
|
|
186
229
|
...(node === lastViolation
|