diff --git a/index.js b/index.js index 95eb7ad..017f37d 100644 --- a/index.js +++ b/index.js @@ -18,14 +18,54 @@ const { socketYmlSchemaV1 } = require('./lib/v1') * @property {boolean} [authenticatedProjectReports] enable/disable authenticated project report URLs */ +/** + * Configures how an issue should be handled by a given layer of configuration. + * - "defer" will cause the issue to bubble up to a higher layer. E.G. socket.yml may defer to organization settings. This acts as if the value is unset. + * - "error" will cause an alert to be shown and require some kind of interaction/setting and will block usage if it is encountered. The interaction may be a prompt, a PR comment, etc. + * - "warn" will cause an alert to be shown but will not require any interaction/setting and will not block usage if it is encountered. + * - "ignore" will cause an issue to not be shown and not require any interaction/setting and will not block usage if it is encountered. + * + * @typedef {'defer' | 'error' | 'warn' | 'ignore'} SocketIssueRuleAction + */ + +/** + * @typedef SocketIssueRuleObject + * @property {SocketIssueRuleAction} [action] + */ + +/** + * @typedef {boolean | SocketIssueRuleObject} SocketIssueRuleValue + */ + /** * @typedef SocketYml * @property {2} version * @property {string[]} projectIgnorePaths - * @property {{ [issueName: string]: boolean }} issueRules + * @property {{ [issueName: string]: SocketIssueRuleValue }} issueRules * @property {SocketYmlGitHub} githubApp */ +/** @type {import('ajv').JSONSchemaType} */ +const socketYmlIssueRule = { + anyOf: [ + { + type: 'boolean', + default: false + }, + { + type: 'object', + properties: { + action: { + type: 'string', + enum: ['defer', 'error', 'warn', 'ignore'], + // note: ajv does not allow this enum to be `null`, this is due to anyOf + nullable: true + } + } + } + ] +} + /** @type {import('ajv').JSONSchemaType} */ const socketYmlSchema = { $schema: 'http://json-schema.org/draft-07/schema#', @@ -40,7 +80,7 @@ const socketYmlSchema = { issueRules: { type: 'object', required: [], - additionalProperties: { type: 'boolean' }, + additionalProperties: socketYmlIssueRule, default: {} }, githubApp: { diff --git a/package.json b/package.json index 9a5e8e0..d56a81f 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "build:2-schema-file": "echo \"console.log(JSON.stringify(require('.').socketYmlSchema, undefined, 2))\" | node > schema.json", "build": "run-s build:*", "check:dependency-check": "dependency-check '*.js' 'test/**/*.js' --no-dev", - "check:installed-check": "installed-check -i eslint-plugin-jsdoc", + "//check:installed-check": "installed-check -i eslint-plugin-jsdoc", "check:lint": "eslint --report-unused-disable-directives .", "check:tsc": "tsc", "check:type-coverage": "type-coverage --detail --strict --at-least 95 --ignore-files 'test/*'", diff --git a/tsconfig.json b/tsconfig.json index a307f0e..abbc0b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,8 @@ "test/**/*", ], "compilerOptions": { + "composite": true, + "allowJs": true, "checkJs": true, "noEmit": true, @@ -15,9 +17,11 @@ "module": "es2022", "moduleResolution": "node", - /* New checks being tried out */ + "strictNullChecks": true, "exactOptionalPropertyTypes": true, "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true,