From b628eb4a0336615cbe8f8cb053692daf30704f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3n=20Molleda?= Date: Mon, 18 Nov 2019 12:37:04 -0800 Subject: [PATCH] Fix: Hide `configuration-all` from the user This configuration is only for internal consumption to get easy access to all the documentation and should never be used by a user as it can cause problems when extending from it. This PR filters it when running `npm init hintrc` and verifies the `.hintrc` doesn't `extends` from it. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Fix #3097 --- packages/create-hintrc/src/create-hintrc.ts | 6 +++++- packages/hint/src/lib/config/config-schema.json | 3 ++- packages/hint/tests/lib/config/config-validator.ts | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/create-hintrc/src/create-hintrc.ts b/packages/create-hintrc/src/create-hintrc.ts index fd16ac8e4c1..85cf35c6fb4 100644 --- a/packages/create-hintrc/src/create-hintrc.ts +++ b/packages/create-hintrc/src/create-hintrc.ts @@ -64,13 +64,17 @@ const extendConfig = async (): Promise => { return null; } - const choices = configPackages.map((pkg) => { + const configNames = configPackages.map((pkg) => { return { name: getConfigurationName(pkg.name), value: pkg.name }; }); + const choices = configNames.filter((config) => { + return config.name !== 'all'; + }); + const questions: inquirer.Questions = [{ choices, message: 'Choose the configuration you want to extend from', diff --git a/packages/hint/src/lib/config/config-schema.json b/packages/hint/src/lib/config/config-schema.json index 808f6f9151f..5ec2bf02c6f 100644 --- a/packages/hint/src/lib/config/config-schema.json +++ b/packages/hint/src/lib/config/config-schema.json @@ -98,7 +98,8 @@ "description": "Base configuration to use.", "type": "array", "items": { - "type": "string" + "type": "string", + "pattern": "^(?!all$).*$" }, "uniqueItems": true }, diff --git a/packages/hint/tests/lib/config/config-validator.ts b/packages/hint/tests/lib/config/config-validator.ts index a9bfc8b9ab5..f0d6ce4cfd0 100644 --- a/packages/hint/tests/lib/config/config-validator.ts +++ b/packages/hint/tests/lib/config/config-validator.ts @@ -64,6 +64,7 @@ const invalidHintsConfigArrayFormArrayInverted = { hints: [[{}, 'no-html-only-headers:error']] }; +const invalidExtends = { extends: ['all'] }; test('If config has an invalid schema, it should return false', (t) => { const valid = configValidator.validateConfig(invalidConfig as any); @@ -118,3 +119,9 @@ test('If the configuration uses shorthands, it should validate', (t) => { t.true(valid); }); + +test('If config extends from "all" is should not validate', (t) => { + const invalid = configValidator.validateConfig(invalidExtends as any); + + t.false(invalid); +});