Skip to content
Permalink
Browse files

Fix: Schema and Types for hints

Close #3348
  • Loading branch information
sarvaje authored and molant committed Nov 18, 2019
1 parent a10d72f commit 7ea9591f38c2a79d9943bcb9ce6303db3a6556fb
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Configuration",
"description": "A configuration file for hint",
"type": "object",
@@ -1,7 +1,7 @@
{
"additionalProperties": false,
"title": "JSON schema for Babel 6+ configuration files",
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"ast": {
@@ -172,4 +172,4 @@
"type": "string"
}
}
}
}
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"definitions": {
"image": {
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "JSON schema for NPM package.json files",
"definitions": {
"person": {
@@ -68,15 +68,15 @@
},
"coreProperties": {
"type": "object",

"patternProperties": {
"^_": {
"description": "Any property starting with _ is valid.",
"additionalProperties": true,
"additionalItems": true
}
},

"properties": {
"name": {
"description": "The name of the package.",
@@ -461,4 +461,4 @@
]
}
]
}
}
@@ -1,6 +1,6 @@
{
"title": "JSON schema for the TypeScript compiler's configuration file",
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",

"definitions": {
"filesDefinition": {
@@ -1,6 +1,6 @@
{
"title": "JSON schema for the TypeScript compiler's configuration file",
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",

"definitions": {
"filesDefinition": {
@@ -16,13 +16,10 @@ const validator = new ajv({ // eslint-disable-line new-cap
$data: true,
allErrors: true,
logger: false,
schemaId: 'id',
useDefaults: true,
verbose: true
} as ajv.Options);

validator.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));

enum ErrorKeyword {
additionalProperties = 'additionalProperties',
anyOf = 'anyOf',
@@ -3,7 +3,7 @@ import test from 'ava';
import { SchemaValidationResult, validate } from '../src';

const baseSchema = {
$schema: 'http://json-schema.org/draft-04/schema#',
$schema: 'http://json-schema.org/draft-07/schema#',
additionalProperties: false,
properties: {
a: {
@@ -23,7 +23,7 @@ const baseSchema = {
};

const schemaTypeRequireAndUniqueItems = {
$schema: 'http://json-schema.org/draft-04/schema#',
$schema: 'http://json-schema.org/draft-07/schema#',
additionalProperties: false,
properties: {
d: {
@@ -65,12 +65,12 @@ export default function normalizeHints(hints: HintsConfigObject | (string | any[
result[hintName] = hintLevel;
} else if (Array.isArray(hint)) {
const [hintKey, hintConfig] = hint;
const { hintName, hintLevel } = normalizeHint(hintKey as string);
const { hintName, hintLevel } = normalizeHint(hintKey);

if (hintConfig) {
result[hintName] = [hintLevel, hintConfig];
} else {
result[hintName] = [hintLevel];
result[hintName] = [hintLevel, {}];
}
} else {
throw new Error(`Invalid hint type specified: "${hint}". Arrays and objects are supported.`);
@@ -64,17 +64,29 @@ export const toAbsolutePaths = (config: UserConfig | null, configRoot: string):

// Update hints
if (config.hints) {
const hints = Object.keys(config.hints);
const hints = Array.isArray(config.hints) ? config.hints : Object.keys(config.hints);

const transformedHints = hints.reduce((newHints, currentHint) => {
const newHint = resolve(currentHint);
if (Array.isArray(config.hints)) {
config.hints = hints.map((currentHint) => {
if (typeof currentHint === 'string') {
return resolve(currentHint);
}

newHints[newHint] = (config.hints as HintsConfigObject)[currentHint];
currentHint[0] = resolve(currentHint[0]);

return newHints;
}, {} as HintsConfigObject);
return currentHint;
});
} else {
const transformedHints = (hints as string[]).reduce((newHints, currentHint) => {
const newHint = resolve(currentHint);

newHints[newHint] = (config.hints as HintsConfigObject)[currentHint];

config.hints = transformedHints;
return newHints;
}, {} as HintsConfigObject);

config.hints = transformedHints;
}
}

return config;
@@ -29,7 +29,7 @@ export type HintConfig = HintSeverity | [HintSeverity, any];
* ```
*/
export type HintsConfigObject = {
[key: string]: HintConfig | HintConfig[];
[key: string]: HintConfig;
};

export type ConnectorOptionsConfig = {
@@ -47,12 +47,16 @@ export type IgnoredUrl = {
hints: string[];
};

type HintConfigArray = [string, { [key: string]: any }];

type HintsConfigArray = (HintConfigArray | string)[];

export type UserConfig = {
browserslist?: string | string[];
connector?: ConnectorConfig | string;
extends?: string[];
formatters?: string[];
hints?: HintsConfigObject | [HintSeverity, HintConfig][];
hints?: HintsConfigObject | HintsConfigArray;
hintsTimeout?: number;
ignoredUrls?: IgnoredUrl[];
language?: string;

0 comments on commit 7ea9591

Please sign in to comment.
You can’t perform that action at this time.