Skip to content

Commit

Permalink
feat: Add types to config-array
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Apr 24, 2024
1 parent 7c431a3 commit 808f96e
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 181 deletions.
10 changes: 6 additions & 4 deletions packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
},
"homepage": "https://github.com/eslint/rewrite#readme",
"scripts": {
"build": "rollup -c",
"prepare": "npm run build",
"build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
"pretest": "npm run build",
"test": "mocha tests/"
},
"keywords": [
Expand All @@ -39,10 +40,11 @@
"minimatch": "^3.0.5"
},
"devDependencies": {
"@types/minimatch": "^3.0.5",
"mocha": "^10.4.0",
"rollup": "^4.16.2",
"typescript": "^5.4.5",
"rollup-plugin-copy": "^3.5.0"
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.4.5"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
Expand Down
23 changes: 17 additions & 6 deletions packages/config-array/src/base-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
* @author Nicholas C. Zakas
*/

//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------

/** @typedef {import("@eslint/object-schema").PropertyDefinition} PropertyDefinition */
/** @typedef {import("@eslint/object-schema").ObjectDefinition} ObjectDefinition */

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

/**
* A strategy that does nothing.
* @type {PropertyDefinition}
*/
const NOOP_STRATEGY = {
required: false,
merge() {
return undefined;
},
validate() { }
validate() {},
};

//------------------------------------------------------------------------------
Expand All @@ -21,7 +32,7 @@ const NOOP_STRATEGY = {

/**
* The base schema that every ConfigArray uses.
* @type Object
* @type {ObjectDefinition}
*/
export const baseSchema = Object.freeze({
name: {
Expand All @@ -30,11 +41,11 @@ export const baseSchema = Object.freeze({
return undefined;
},
validate(value) {
if (typeof value !== 'string') {
throw new TypeError('Property must be a string.');
if (typeof value !== "string") {
throw new TypeError("Property must be a string.");
}
}
},
},
files: NOOP_STRATEGY,
ignores: NOOP_STRATEGY
ignores: NOOP_STRATEGY,
});
Loading

0 comments on commit 808f96e

Please sign in to comment.