Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public constructor(engine: Engine) {
super(engine, 'package-json');
// JSON Schema from http://json.schemastore.org/package
this.schema = loadJSONFile(path.join(__dirname, 'schema.json'));
// package.json => type: 'json' (file type from extention).
engine.on('fetch::end::json', this.parsePackageJson.bind(this));
}
export const tryToLoadFrom = (resourcePath: string): any => {
// This is exported so it's easier to stub during tests
let builder: any = null;
/*
* We could be loading a config file that points to a path (thus a JSON).
* `require` will try to load `.js`, `.json`, `.node` so it will fail and
* we have to manually do this
*/
try {
const resource = loadJSONFile(resourcePath);
return resource;
} catch (e) {
debug(`${resourcePath} is not a JSON file, trying to load it normally`);
}
try {
/*
* The following link has more info on how `require` resolves modules:
* http://nodejs.org/dist/latest-v8.x/docs/api/modules.html#modules_all_together
*/
const resource = requirePackage(resourcePath);
builder = resource.default || resource;
} catch (e) {
if (packages.length === 0) {
return Promise.resolve(true);
}
const hintLocalPath = path.join(currentWorkingDir, 'node_modules', 'hint', 'package.json');
// Check if hint is installed locally.
const global: boolean = !fs.existsSync(hintLocalPath); // eslint-disable-line no-sync
/** package manager to install the packages. */
const packageManagerChoice = (!global && await hasYarnLock(currentWorkingDir)) ? 'yarn' : 'npm';
if (!global) {
try {
const packagePath = findPackageRoot(currentWorkingDir);
const jsonContent = loadJSONFile(path.join(packagePath, 'package.json'));
// If `hint` is a devDependency, then set all packages as devDependencies.
isDev = jsonContent.devDependencies && jsonContent.devDependencies.hasOwnProperty('hint');
} catch (err) {
// Even if `hint` is installed locally, package.json could not exist in the current working directory.
isDev = false;
}
}
const installCommand = {
npm: `npm install${global ? ' --global' : ''}${isDev ? ' --save-dev' : ''}`,
yarn: `yarn add${isDev ? ' --dev' : ''}`
};
const command = `${installCommand[packageManagerChoice]} ${packages.join(' ')}`;
import * as path from 'path';
import * as moment from 'moment';
import cloneDeep = require('lodash/cloneDeep');
import { Category, Problem, Severity } from '@hint/utils-types';
import { loadJSONFile } from '@hint/utils-fs';
import { getCategoryName } from '@hint/utils-i18n';
import { FormatterOptions } from 'hint';
const thirdPartyServices = loadJSONFile(path.join(__dirname, 'configs', 'third-party-service-config.json'));
const categoryImages = loadJSONFile(path.join(__dirname, 'configs', 'category-images.json'));
const hintsWithoutDocs = ['optimize-image'];
/** Third party logo type. */
type ThirdPartyLogo = {
name: string;
url: string;
alt: string;
};
/** Third party information. */
type ThirdPartyInfo = {
logo: ThirdPartyLogo;
link: string;
details?: boolean;
};
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;
};
public static loadConfigFile(filePath: string): UserConfig | null {
let config: UserConfig | null;
switch (path.extname(filePath)) {
case '':
case '.json':
if (path.basename(filePath) === 'package.json') {
config = loadPackageJSONConfigFile(filePath);
} else {
config = loadJSONFile(filePath);
}
break;
case '.js':
config = loadJSFile(filePath);
break;
default:
config = null;
}
config = this.toAbsolutePaths(config, filePath);
return config;
}
const loadPackageJSONConfigFile = (filePath: string): UserConfig => {
debug(`Loading package.json config file: ${filePath}`);
try {
return loadJSONFile(filePath).hintConfig || null;
} catch (e) {
debug(`Error reading package.json file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}
};
public constructor(engine: Engine) {
super(engine, 'typescript-config');
this.schema = loadJSONFile(this.schemaPath);
engine.on('fetch::end::*', this.parseTypeScript.bind(this));
}
import * as path from 'path';
import * as moment from 'moment';
import cloneDeep = require('lodash/cloneDeep');
import { Category, Problem, Severity } from '@hint/utils-types';
import { loadJSONFile } from '@hint/utils-fs';
import { getCategoryName } from '@hint/utils-i18n';
import { FormatterOptions } from 'hint';
const thirdPartyServices = loadJSONFile(path.join(__dirname, 'configs', 'third-party-service-config.json'));
const categoryImages = loadJSONFile(path.join(__dirname, 'configs', 'category-images.json'));
const hintsWithoutDocs = ['optimize-image'];
/** Third party logo type. */
type ThirdPartyLogo = {
name: string;
url: string;
alt: string;
};
/** Third party information. */
type ThirdPartyInfo = {
logo: ThirdPartyLogo;
link: string;
details?: boolean;
};
public constructor(engine: Engine) {
super(engine, 'babel-config');
this.schema = loadJSONFile(path.join(__dirname, 'schema.json'));
/**
* package.json => type: 'json' (file type from extention).
*/
engine.on('fetch::end::json', this.parseBabelConfig.bind(this));
}