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

chore: switch to eslint flat config #60

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 0 additions & 28 deletions .eslintrc.json

This file was deleted.

33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import eslintConfigESLint from "eslint-config-eslint";
import globals from "globals";

export default [
{
ignores: [
"dist/",
"coverage/"
]
},
...eslintConfigESLint,
{
linterOptions: {
reportUnusedDisableDirectives: "error"
},
settings: {
jsdoc: {
preferredTypes: {
Object: "object",
"object<>": "Object"
}
}
}
},
{
files: ["tests/lib/**"],
languageOptions: {
globals: {
...globals.mocha
}
}
}
];
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function filterKey(key) {
return !KEY_BLACKLIST.has(key) && key[0] !== "_";
}


/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
*/
/**
* Get visitor keys of a given node.
* @param {object} node The AST node to get keys.
Expand All @@ -32,18 +36,16 @@ function filterKey(key) {
export function getKeys(node) {
return Object.keys(node).filter(filterKey);
}
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly` */

// Disable valid-jsdoc rule because it reports syntax error on the type of @returns.
// eslint-disable-next-line valid-jsdoc
/**
* Make the union set with `KEYS` and given keys.
* @param {VisitorKeys} additionalKeys The additional keys.
* @returns {VisitorKeys} The union set.
*/
export function unionWith(additionalKeys) {
const retv = /** @type {{
[type: string]: ReadonlyArray<string>
}} */ (Object.assign({}, KEYS));
const retv = /** @type {{ [type: string]: ReadonlyArray<string> }} */
(Object.assign({}, KEYS));

for (const type of Object.keys(additionalKeys)) {
if (Object.prototype.hasOwnProperty.call(retv, type)) {
Expand Down
4 changes: 4 additions & 0 deletions lib/visitor-keys.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* eslint-disable jsdoc/valid-types -- doesn't allow `readonly`.
TODO: remove eslint-disable when https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/164 is fixed
*/
/**
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
*/
/* eslint-enable jsdoc/valid-types -- doesn't allow `readonly string[]`. TODO: check why */

/**
* @type {VisitorKeys}
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
"@typescript-eslint/parser": "^5.14.0",
"c8": "^7.11.0",
"chai": "^4.3.6",
"eslint": "^7.29.0",
"eslint-config-eslint": "^7.0.0",
"eslint-plugin-jsdoc": "^35.4.0",
"eslint-plugin-node": "^11.1.0",
"eslint": "^8.56.0",
"eslint-config-eslint": "^9.0.0",
"eslint-release": "^3.2.0",
"esquery": "^1.4.0",
"globals": "^13.21.0",
"json-diff": "^0.7.3",
"mocha": "^9.2.1",
"opener": "^1.5.2",
Expand Down
5 changes: 0 additions & 5 deletions tests/lib/.eslintrc.json

This file was deleted.

3 changes: 1 addition & 2 deletions tests/lib/commonjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @author Mike Reinstein
*/

// eslint-disable-next-line strict
"use strict";

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -49,7 +48,7 @@ describe("commonjs", () => {

for (const type of Object.keys(additionalKeys)) {
for (const key of additionalKeys[type]) {
assert(unionKeys[type].indexOf(key) !== -1, `'${key}' should be included in '${type}'.`);
assert(unionKeys[type].includes(key), `'${key}' should be included in '${type}'.`);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ describe("eslint-visitor-keys", () => {
it("should include all keys of lib/visitor-keys.js", () => {
for (const type of Object.keys(keys)) {
for (const key of keys[type]) {
assert(unionKeys[type].indexOf(key) !== -1, `'${key}' should be included in '${type}'.`);
assert(unionKeys[type].includes(key), `'${key}' should be included in '${type}'.`);
}
}
});

it("should include all additional keys", () => {
for (const type of Object.keys(additionalKeys)) {
for (const key of additionalKeys[type]) {
assert(unionKeys[type].indexOf(key) !== -1, `'${key}' should be included in '${type}'.`);
assert(unionKeys[type].includes(key), `'${key}' should be included in '${type}'.`);
}
}
});
Expand Down
20 changes: 10 additions & 10 deletions tools/get-keys-from-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function alphabetizeKeyInterfaces(initialNodes) {
* @param {Node} declNode The TS declaration node
* @param {Function} handler The callback
* @returns {any[]} Return value of handler
* @throws {Error} If it finds an unknown type parameter.
*/
function traverseExtends(declNode, handler) {
const ret = [];
Expand Down Expand Up @@ -209,6 +210,7 @@ function traverseProperties(tsDeclarationNode, handler) {
* @param {string} code TypeScript declaration file as code to parse.
* @param {{supplementaryDeclarations: Node[]}} [options] The options
* @returns {VisitorKeysExport} The built visitor keys
* @throws {Error} If it finds an unknown type.
*/
function getKeysFromTs(code, {

Expand Down Expand Up @@ -285,6 +287,7 @@ function getKeysFromTs(code, {
* @param {string} cfg.property The property name
* @param {Node} cfg.tsAnnotation The annotation node
* @returns {boolean} Whether has a traverseable type
* @throws {Error} If it finds an unknown type.
*/
function hasValidType({ property, tsAnnotation }) {
const tsPropertyType = tsAnnotation.type;
Expand All @@ -302,7 +305,6 @@ function getKeysFromTs(code, {
// Ok, but not sufficient
return false;
case "TSUnionType":
// eslint-disable-next-line no-use-before-define -- Circular
return tsAnnotation.types.some(annType => hasValidType({
property: "type",
tsAnnotation: annType
Expand All @@ -316,6 +318,7 @@ function getKeysFromTs(code, {
* Whether the interface has a valid type ancestor
* @param {string} interfaceName The interface to check
* @returns {void}
* @throws {Error} If it finds an unknown type.
*/
function hasValidTypeAncestor(interfaceName) {
let decl = findTsInterfaceDeclaration(interfaceName);
Expand Down Expand Up @@ -515,16 +518,13 @@ function getKeysFromTs(code, {
}

/**
* @typedef {{tsInterfaceDeclarations: {
* allTsInterfaceDeclarations: {
* Node[],
* keys: KeysStrict
* },
* exportedTsInterfaceDeclarations:
* Node[],
* keys: KeysStrict
* @typedef {{
* keys: KeysStrict,
* tsInterfaceDeclarations: {
* allTsInterfaceDeclarations: Node[],
* exportedTsInterfaceDeclarations: Node[]
* }
* }}} VisitorKeysExport
* }} VisitorKeysExport
*/

/**
Expand Down