Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump eslint-config-openlayers from 19.0.0 to 20.0.0 #70

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint updates
  • Loading branch information
tschaub committed Dec 9, 2024
commit 6196e819b616e9345217adc52fefb63d5ebf43fc
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set Node.js Version
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '22'

- name: Install Dependencies
run: npm ci
Expand Down
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import openlayers from 'eslint-config-openlayers';

/**
* @type {Array<import("eslint").Linter.Config>}
*/
export default [
...openlayers,
];
318 changes: 159 additions & 159 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require('string.prototype.matchall').shim();
const path = require('path');
const fs = require('fs');
const env = require('jsdoc/env'); // eslint-disable-line import/no-unresolved
const path = require('path');
const addInherited = require('jsdoc/augment').addInherited; // eslint-disable-line import/no-unresolved
const env = require('jsdoc/env'); // eslint-disable-line import/no-unresolved

const importRegEx =
/import\(["']([^"']*)["']\)(?:\.([^ \.\|\}><,\)=#\n]*))?([ \.\|\}><,\)=#\n])/g;
Expand Down Expand Up @@ -117,7 +117,7 @@ function getModuleInfo(modulePath, parser) {

if (!moduleInfos[modulePath]) {
if (!fileNodes[modulePath]) {
const file = fs.readFileSync(modulePath, 'UTF-8');
const file = fs.readFileSync(modulePath, {encoding: 'utf8'});

fileNodes[modulePath] = parser.astBuilder.build(file, modulePath);
}
Expand Down Expand Up @@ -193,162 +193,6 @@ function replaceByIndices(text, replacements) {
return replacedText;
}

exports.defineTags = function (dictionary) {
const tags = [
'type',
'typedef',
'property',
'return',
'param',
'template',
'default',
'member',
];

tags.forEach(function (tagName) {
const tag = dictionary.lookUp(tagName);
const oldOnTagText = tag.onTagText;

/**
* @param {string} tagText The tag text
* @return {string} The modified tag text
*/
tag.onTagText = function (tagText) {
if (oldOnTagText) {
tagText = oldOnTagText.apply(this, arguments);
}

const startIndex = tagText.search('{');
if (startIndex === -1) {
return tagText;
}

const len = tagText.length;

/** @type {Array<[number, number, string]>} */
let replacements = [];
let openCurly = 0;
let openSquare = 0;
let openRound = 0;
let isWithinString = false;
let quoteChar = '';
let i = startIndex;
let functionStartIndex;

while (i < len) {
switch (tagText[i]) {
case '\\':
// Skip escaped character
++i;
break;
case '"':
case "'":
if (isWithinString && quoteChar === tagText[i]) {
isWithinString = false;
quoteChar = '';
} else if (!isWithinString) {
isWithinString = true;
quoteChar = tagText[i];
}

break;
case ';':
// Replace interface-style semi-colon separators with commas
if (!isWithinString && openCurly > 1) {
const isTrailingSemiColon = /^\s*}/.test(tagText.slice(i + 1));

replacements.push([i, i + 1, isTrailingSemiColon ? '' : ',']);
}

break;
case '(':
if (openRound === 0) {
functionStartIndex = i;
}

++openRound;

break;
case ')':
if (!--openRound) {
// If round brackets form a function
const returnMatch = tagText.slice(i + 1).match(/^\s*(:|=>)/);

// Replace TS inline function syntax with JSDoc
if (returnMatch) {
const functionEndIndex = i + returnMatch[0].length + 1;
const hasFunctionKeyword = /\bfunction\s*$/.test(
tagText.slice(0, functionStartIndex),
);

// Filter out any replacements that are within the function
replacements = replacements.filter(([startIndex]) => {
return startIndex < functionStartIndex || startIndex > i;
});

replacements.push([
functionStartIndex,
functionEndIndex,
hasFunctionKeyword ? '():' : 'function():',
]);
}

functionStartIndex = null;
}

break;
case '[':
if (
isWithinString ||
variableNameRegEx.test(tagText.charAt(i - 1))
) {
break;
}
++openSquare;
break;
case ']':
if (isWithinString) {
break;
}
if (!--openSquare) {
// Replace [type1, type2] tuples with Array
replacements.push([startIndex + 1, i + 1, 'Array']);
}
break;
case '{':
++openCurly;
break;
case '}':
if (!--openCurly) {
const head = tagText.slice(0, startIndex);
const tail = tagText.slice(i + 1);

const replaced = replaceByIndices(
tagText.slice(startIndex, i + 1),
replacements,
)
// Replace `templateliteral` with 'templateliteral'
.replace(/`([^`]*)`/g, "'$1'")
// Bracket notation to dot notation
.replace(
/(\w+|>|\)|\])\[(?:'([^']+)'|"([^"]+)")\]/g,
'$1.$2$3',
);

return head + replaced + tail;
}

break;
default:
break;
}
++i;
}
throw new Error("Missing closing '}'");
};
});
};

exports.astNodeVisitor = {
visitNode: function (node, e, parser, currentSourceName) {
if (node.type === 'File') {
Expand Down Expand Up @@ -655,6 +499,162 @@ exports.astNodeVisitor = {
},
};

exports.defineTags = function (dictionary) {
const tags = [
'type',
'typedef',
'property',
'return',
'param',
'template',
'default',
'member',
];

tags.forEach(function (tagName) {
const tag = dictionary.lookUp(tagName);
const oldOnTagText = tag.onTagText;

/**
* @param {string} tagText The tag text
* @return {string} The modified tag text
*/
tag.onTagText = function (tagText) {
if (oldOnTagText) {
tagText = oldOnTagText.apply(this, arguments);
}

const startIndex = tagText.search('{');
if (startIndex === -1) {
return tagText;
}

const len = tagText.length;

/** @type {Array<[number, number, string]>} */
let replacements = [];
let openCurly = 0;
let openSquare = 0;
let openRound = 0;
let isWithinString = false;
let quoteChar = '';
let i = startIndex;
let functionStartIndex;

while (i < len) {
switch (tagText[i]) {
case '\\':
// Skip escaped character
++i;
break;
case '"':
case "'":
if (isWithinString && quoteChar === tagText[i]) {
isWithinString = false;
quoteChar = '';
} else if (!isWithinString) {
isWithinString = true;
quoteChar = tagText[i];
}

break;
case ';':
// Replace interface-style semi-colon separators with commas
if (!isWithinString && openCurly > 1) {
const isTrailingSemiColon = /^\s*}/.test(tagText.slice(i + 1));

replacements.push([i, i + 1, isTrailingSemiColon ? '' : ',']);
}

break;
case '(':
if (openRound === 0) {
functionStartIndex = i;
}

++openRound;

break;
case ')':
if (!--openRound) {
// If round brackets form a function
const returnMatch = tagText.slice(i + 1).match(/^\s*(:|=>)/);

// Replace TS inline function syntax with JSDoc
if (returnMatch) {
const functionEndIndex = i + returnMatch[0].length + 1;
const hasFunctionKeyword = /\bfunction\s*$/.test(
tagText.slice(0, functionStartIndex),
);

// Filter out any replacements that are within the function
replacements = replacements.filter(([startIndex]) => {
return startIndex < functionStartIndex || startIndex > i;
});

replacements.push([
functionStartIndex,
functionEndIndex,
hasFunctionKeyword ? '():' : 'function():',
]);
}

functionStartIndex = null;
}

break;
case '[':
if (
isWithinString ||
variableNameRegEx.test(tagText.charAt(i - 1))
) {
break;
}
++openSquare;
break;
case ']':
if (isWithinString) {
break;
}
if (!--openSquare) {
// Replace [type1, type2] tuples with Array
replacements.push([startIndex + 1, i + 1, 'Array']);
}
break;
case '{':
++openCurly;
break;
case '}':
if (!--openCurly) {
const head = tagText.slice(0, startIndex);
const tail = tagText.slice(i + 1);

const replaced = replaceByIndices(
tagText.slice(startIndex, i + 1),
replacements,
)
// Replace `templateliteral` with 'templateliteral'
.replace(/`([^`]*)`/g, "'$1'")
// Bracket notation to dot notation
.replace(
/(\w+|>|\)|\])\[(?:'([^']+)'|"([^"]+)")\]/g,
'$1.$2$3',
);

return head + replaced + tail;
}

break;
default:
break;
}
++i;
}
throw new Error("Missing closing '}'");
};
});
};

exports.handlers = {
parseComplete: function (e) {
// Build inheritance chain after adding @extends annotations
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Plugin to make TypeScript's JSDoc type annotations work with JSDoc",
"main": "index.js",
"scripts": {
"lint": "eslint index.js",
"lint": "eslint index.js test",
"pretest": "npm run lint",
"test": "node test/test.js"
},
Expand All @@ -31,8 +31,5 @@
"eslint-config-openlayers": "^20.0.0",
"fs-extra": "^11.1.0",
"jsdoc": "^4.0.2"
},
"eslintConfig": {
"extends": "openlayers"
}
}
Loading
Loading