Skip to content
Permalink
Browse files

Breaking: Remove json specific parser form hint

  • Loading branch information
sarvaje committed Nov 5, 2019
1 parent 28fcba4 commit c177cc96e898c40ac66c02304e7beafa25cfa6ac
Showing with 0 additions and 277 deletions.
  1. +0 −72 packages/hint/src/lib/types/parser.ts
  2. +0 −205 packages/hint/tests/lib/types/parser.ts
@@ -1,22 +1,6 @@
import * as path from 'path';

import merge = require('lodash/merge');

import { loadJSONFile } from '@hint/utils-fs/dist/src/load-json-file';
import { asPathString } from '@hint/utils-network/dist/src/as-path-string';
import { getAsUri } from '@hint/utils-network/dist/src/as-uri';

import { Engine } from '../engine';
import { Events } from './events';

export interface IParsingError extends Error {
resource: string;
}

export type ExtendableConfiguration = {
extends: string;
};

export interface IParserConstructor {
new(engine: Engine): Parser;
}
@@ -26,62 +10,6 @@ export abstract class Parser<E extends Events = Events> {
protected engine: Engine<E>;
protected name: string;

protected finalConfig<T extends ExtendableConfiguration>(config: T, resource: string): T | IParsingError {
if (!config.extends) {
return config;
}

const configIncludes = [];

// `resource` has already been loaded to provide `config` so `getAsUri` won't be null.
let configPath = asPathString(getAsUri(resource)!);

/*
* `configPath` will have the format c:/path or /path
* depending on what OS we are running sonar.
* In case that we are running on Windows, we need
* to normalize the path to c:\path before continue.
*/
configIncludes.push(path.normalize(configPath));

let finalConfigJSON: T = merge({}, config);

while (finalConfigJSON.extends) {
const lastPath = configPath;
const configDir = path.dirname(configPath);

configPath = path.resolve(configDir, finalConfigJSON.extends);

if (configIncludes.includes(configPath)) {

const error = new Error(`Circular reference found in file ${lastPath}`) as IParsingError;
const originalPathUri = getAsUri(configIncludes[0]);

error.resource = originalPathUri && originalPathUri.toString() || lastPath;

return error;
}

delete finalConfigJSON.extends;

try {
const extendedConfig = loadJSONFile(configPath);

configIncludes.push(configPath);

finalConfigJSON = merge({}, extendedConfig, finalConfigJSON);
} catch (err) {
const lastPathUri = getAsUri(lastPath);

err.resource = lastPathUri && lastPathUri.toString() || lastPath;

return err;
}
}

return finalConfigJSON;
}

/* istanbul ignore next */
public constructor(engine: Engine<E>, parseEventType: string) {
this.engine = engine;

This file was deleted.

0 comments on commit c177cc9

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