Permalink
Browse files

Breaking: Rename `parse::*::end`, etc. to `parse:πŸ”š:*`

Change made in order to be more consistent with `fetch` event names.

Close #1397
  • Loading branch information...
antross authored and alrra committed Oct 15, 2018
1 parent d181168 commit 8499d5ca6519d859d81d5126cfd9886bee5d3091
Showing with 383 additions and 305 deletions.
  1. +1 βˆ’1 packages/connector-local/src/connector.ts
  2. +28 βˆ’11 packages/create-parser/src/templates/parser.hbs
  3. +5 βˆ’5 packages/hint-babel-config/src/is-valid.ts
  4. +1 βˆ’1 packages/hint-manifest-app-name/src/hint.ts
  5. +13 βˆ’14 packages/hint-manifest-is-valid/src/hint.ts
  6. +1 βˆ’1 packages/hint-minified-js/src/hint.ts
  7. +1 βˆ’1 packages/hint-typescript-config/src/consistent-casing.ts
  8. +2 βˆ’2 packages/hint-typescript-config/src/import-helpers.ts
  9. +5 βˆ’5 packages/hint-typescript-config/src/is-valid.ts
  10. +1 βˆ’1 packages/hint-typescript-config/src/no-comments.ts
  11. +1 βˆ’1 packages/hint-typescript-config/src/strict.ts
  12. +1 βˆ’1 packages/hint-typescript-config/src/target.ts
  13. +2 βˆ’2 packages/hint-webpack-config/src/config-exists.ts
  14. +2 βˆ’2 packages/hint-webpack-config/src/is-installed.ts
  15. +2 βˆ’2 packages/hint-webpack-config/src/is-valid.ts
  16. +4 βˆ’6 packages/hint-webpack-config/src/module-esnext-typescript.ts
  17. +4 βˆ’6 packages/hint-webpack-config/src/modules-false-babel.ts
  18. +2 βˆ’2 packages/hint-webpack-config/src/no-devtool-in-prod.ts
  19. +29 βˆ’40 packages/hint/docs/contributor-guide/getting-started/events.md
  20. +47 βˆ’1 packages/hint/docs/user-guide/concepts/parsers.md
  21. +1 βˆ’2 packages/hint/src/lib/engine.ts
  22. +2 βˆ’2 packages/hint/src/lib/hint-context.ts
  23. +1 βˆ’1 packages/hint/src/lib/types/events.ts
  24. +2 βˆ’2 packages/hint/src/lib/types/parser.ts
  25. +7 βˆ’7 packages/parser-babel-config/README.md
  26. +5 βˆ’4 packages/parser-babel-config/src/parser.ts
  27. +7 βˆ’7 packages/parser-babel-config/src/types.ts
  28. +15 βˆ’15 packages/parser-babel-config/tests/tests.ts
  29. +13 βˆ’8 packages/parser-css/README.md
  30. +3 βˆ’1 packages/parser-css/src/parser.ts
  31. +2 βˆ’1 packages/parser-css/src/types.ts
  32. +4 βˆ’2 packages/parser-css/tests/basic-tests.ts
  33. +8 βˆ’8 packages/parser-css/tests/interface-tests.ts
  34. +3 βˆ’1 packages/parser-html/src/parser.ts
  35. +2 βˆ’1 packages/parser-html/src/types.ts
  36. +20 βˆ’19 packages/parser-html/tests/parser.ts
  37. +9 βˆ’2 packages/parser-javascript/README.md
  38. +3 βˆ’1 packages/parser-javascript/src/parser.ts
  39. +2 βˆ’1 packages/parser-javascript/src/types.ts
  40. +12 βˆ’8 packages/parser-javascript/tests/tests.ts
  41. +6 βˆ’7 packages/parser-manifest/README.md
  42. +10 βˆ’16 packages/parser-manifest/src/parser.ts
  43. +8 βˆ’10 packages/parser-manifest/src/types.ts
  44. +14 βˆ’13 packages/parser-manifest/tests/tests.ts
  45. +7 βˆ’7 packages/parser-typescript-config/README.md
  46. +5 βˆ’4 packages/parser-typescript-config/src/parser.ts
  47. +7 βˆ’7 packages/parser-typescript-config/src/types.ts
  48. +11 βˆ’11 packages/parser-typescript-config/tests/tests.ts
  49. +5 βˆ’5 packages/parser-webpack-config/README.md
  50. +12 βˆ’4 packages/parser-webpack-config/src/parser.ts
  51. +7 βˆ’8 packages/parser-webpack-config/src/types.ts
  52. +18 βˆ’15 packages/parser-webpack-config/tests/webpack-config.ts
@@ -58,7 +58,7 @@ export default class LocalConnector implements IConnector {
this.filesPattern = this.getFilesPattern();
this.engine = engine;
this.engine.on('parse::html::end', this.onParseHTML.bind(this));
this.engine.on('parse::end::html', this.onParseHTML.bind(this));
}
/*
@@ -1,6 +1,26 @@
import { Event, {{#each eventTypes}}{{this}}, {{/each}}Parser } from 'hint/dist/src/lib/types';
import { Engine } from 'hint/dist/src/lib/engine';
/*
* Extend `Event` to add information neeeded by hints.
* i.e.
* type ManifestParsed = Event & {
* sourceCode: any;
* }
*/
export type {{capitalizedName}}Parsed = Event & {
// Extend `Event` to add the information you will need in your hints.
};
/*
* Extend `Events` to declare new events emitted by this parser.
*/
export type {{capitalizedName}}Events = Events & {
'parse::end::{{../normalizedName}}': {{capitalizedName}}Parsed;
'parse::start::{{../normalizedName}}': Event;
};
export default class {{capitalizedName}} extends Parser {
public constructor(engine: Engine) {
super(engine);
@@ -12,17 +32,14 @@ export default class {{capitalizedName}} extends Parser {
{{#each events}}
private async {{handler}}({{varName}}: {{type}}) {
/*
* You can extend Event to add the information
* you will need in you hints.
* i.e.
* type ScriptParse = Event & {
* sourceCode: any;
* }
*/
const eventData: Event = {{varName}};
await this.engine.emitAsync('parse::{{../normalizedName}}', eventData);
await this.engine.emitAsync('parse::start::{{../normalizedName}}', { {{varName}}.resource });
// TODO: Parse the resource.
const eventData: {{capitalizedName}}Parsed = {{varName}};
await this.engine.emitAsync('parse::end::{{../normalizedName}}', eventData);
}
{{/each}}
}
@@ -39,7 +39,7 @@ export default class BabelConfigIsValidHint implements IHint {
const invalidSchema = async (fetchEnd: BabelConfigInvalidSchema) => {
const { errors, prettifiedErrors, resource } = fetchEnd;
debug(`parse::babel-config::error::schema received`);
debug(`parse::error::babel-config::schema received`);
for (let i = 0; i < errors.length; i++) {
const message = prettifiedErrors[i];
@@ -49,9 +49,9 @@ export default class BabelConfigIsValidHint implements IHint {
}
};
context.on('parse::babel-config::error::json', invalidJSONFile);
context.on('parse::babel-config::error::circular', invalidJSONFile);
context.on('parse::babel-config::error::extends', invalidJSONFile);
context.on('parse::babel-config::error::schema', invalidSchema);
context.on('parse::error::babel-config::json', invalidJSONFile);
context.on('parse::error::babel-config::circular', invalidJSONFile);
context.on('parse::error::babel-config::extends', invalidJSONFile);
context.on('parse::error::babel-config::schema', invalidSchema);
}
}
@@ -119,6 +119,6 @@ export default class ManifestAppNameHint implements IHint {
await checkIfPropertyValueIsUnderLimit(resource, shortName, 'short_name', shortNameLengthLimit, getLocation);
};
context.on('parse::manifest::end', validate);
context.on('parse::end::manifest', validate);
}
}
@@ -80,7 +80,7 @@ export default class ManifestIsValidHint implements IHint {
color.model === 'hwb';
};
const checkColors = async (resource: string, element: IAsyncHTMLElement | null, manifest: Manifest, getLocation: IJSONLocationFunction) => {
const checkColors = async (resource: string, manifest: Manifest, getLocation: IJSONLocationFunction) => {
const colorProperties = [
'background_color',
'theme_color'
@@ -97,55 +97,54 @@ export default class ManifestIsValidHint implements IHint {
const color = parseColor(normalizedColorValue);
if (color === null) {
await context.report(resource, element, `Web app manifest should not have invalid value '${colorValue}' for property '${property}'.`, undefined, getLocation(property) || undefined);
await context.report(resource, null, `Web app manifest should not have invalid value '${colorValue}' for property '${property}'.`, undefined, getLocation(property) || undefined);
continue;
}
if (isNotSupportedColorValue(color, normalizedColorValue)) {
await context.report(resource, element, `Web app manifest should not have unsupported value '${colorValue}' for property '${property}'.`, undefined, getLocation(property) || undefined);
await context.report(resource, null, `Web app manifest should not have unsupported value '${colorValue}' for property '${property}'.`, undefined, getLocation(property) || undefined);
}
}
};
const checkLang = async (resource: string, element: IAsyncHTMLElement | null, manifest: Manifest, getLocation: IJSONLocationFunction) => {
const checkLang = async (resource: string, manifest: Manifest, getLocation: IJSONLocationFunction) => {
const lang = manifest.lang;
if (lang && !bcp47(lang)) {
await context.report(resource, element, `Web app manifest should not have invalid value '${manifest.lang}' for property 'lang'.`, undefined, getLocation('lang') || undefined);
await context.report(resource, null, `Web app manifest should not have invalid value '${manifest.lang}' for property 'lang'.`, undefined, getLocation('lang') || undefined);
}
};
const handleInvalidJSON = async (manifestInvalidJSON: ManifestInvalidJSON) => {
const { resource, element } = manifestInvalidJSON;
const { resource } = manifestInvalidJSON;
await context.report(resource, element, `Web app manifest should contain valid JSON.`);
await context.report(resource, null, `Web app manifest should contain valid JSON.`);
};
const handleInvalidSchema = async (manifestInvalidSchemaEvent: ManifestInvalidSchema) => {
for (let i = 0; i < manifestInvalidSchemaEvent.prettifiedErrors.length; i++) {
const error = manifestInvalidSchemaEvent.prettifiedErrors[i];
const location = manifestInvalidSchemaEvent.errors[i].location;
await context.report(manifestInvalidSchemaEvent.resource, manifestInvalidSchemaEvent.element, error, undefined, location);
await context.report(manifestInvalidSchemaEvent.resource, null, error, undefined, location);
}
};
const validateOtherProperties = async (manifestParsed: ManifestParsed) => {
const {
element,
getLocation,
parsedContent: manifest,
resource
} = manifestParsed;
// Additional checks not covered by the schema.
await checkLang(resource, element, manifest, getLocation);
await checkColors(resource, element, manifest, getLocation);
await checkLang(resource, manifest, getLocation);
await checkColors(resource, manifest, getLocation);
};
context.on('parse::manifest::end', validateOtherProperties);
context.on('parse::manifest::error::json', handleInvalidJSON);
context.on('parse::manifest::error::schema', handleInvalidSchema);
context.on('parse::end::manifest', validateOtherProperties);
context.on('parse::error::manifest::json', handleInvalidJSON);
context.on('parse::error::manifest::schema', handleInvalidSchema);
}
}
@@ -62,6 +62,6 @@ export default class MinifiedJsHint implements IHint {
}
};
context.on('parse::javascript::end', validateContentMinified);
context.on('parse::end::javascript', validateContentMinified);
}
}
@@ -29,6 +29,6 @@ export default class TypeScriptConfigConsistentCasing implements IHint {
public constructor(context: HintContext<TypeScriptConfigEvents>) {
const validate = configChecker('compilerOptions.forceConsistentCasingInFileNames', true, 'The compiler option "forceConsistentCasingInFileNames" should be enabled to reduce issues when working with different OSes.', context);
context.on('parse::typescript-config::end', validate);
context.on('parse::end::typescript-config', validate);
}
}
@@ -54,7 +54,7 @@ export default class TypeScriptConfigImportHelpers implements IHint {
}
};
context.on('parse::typescript-config::end', validate);
context.on('parse::typescript-config::end', validateTslibInstalled);
context.on('parse::end::typescript-config', validate);
context.on('parse::end::typescript-config', validateTslibInstalled);
}
}
@@ -45,7 +45,7 @@ export default class TypeScriptConfigIsValid implements IHint {
const invalidSchema = async (fetchEnd: TypeScriptConfigInvalidSchema) => {
const { errors, prettifiedErrors, resource } = fetchEnd;
debug(`parse::typescript-config::error::schema received`);
debug(`parse::error::typescript-config::schema received`);
for (let i = 0; i < errors.length; i++) {
const message = prettifiedErrors[i];
@@ -55,9 +55,9 @@ export default class TypeScriptConfigIsValid implements IHint {
}
};
context.on('parse::typescript-config::error::json', invalidJSONFile);
context.on('parse::typescript-config::error::circular', invalidJSONFile);
context.on('parse::typescript-config::error::extends', invalidJSONFile);
context.on('parse::typescript-config::error::schema', invalidSchema);
context.on('parse::error::typescript-config::json', invalidJSONFile);
context.on('parse::error::typescript-config::circular', invalidJSONFile);
context.on('parse::error::typescript-config::extends', invalidJSONFile);
context.on('parse::error::typescript-config::schema', invalidSchema);
}
}
@@ -31,6 +31,6 @@ export default class TypeScriptConfigNoComments implements IHint {
public constructor(context: HintContext<TypeScriptConfigEvents>) {
const validate = configChecker('compilerOptions.removeComments', true, 'The compiler option "removeComments" should be enabled to reduce the output size.', context);
context.on('parse::typescript-config::end', validate);
context.on('parse::end::typescript-config', validate);
}
}
@@ -30,6 +30,6 @@ export default class TypeScriptConfigStrict implements IHint {
public constructor(context: HintContext<TypeScriptConfigEvents>) {
const validate = configChecker('compilerOptions.strict', true, 'The compiler option "strict" should be enabled to reduce type errors.', context);
context.on('parse::typescript-config::end', validate);
context.on('parse::end::typescript-config', validate);
}
}
@@ -244,6 +244,6 @@ export default class TypeScriptConfigTarget implements IHint {
}
};
context.on('parse::typescript-config::end', validate);
context.on('parse::end::typescript-config', validate);
}
}
@@ -31,11 +31,11 @@ export default class WebpackConfigConfigExists implements IHint {
public constructor(context: HintContext<WebpackConfigEvents>) {
const notFound = async () => {
debug(`parse::webpack-config::error::not-found received`);
debug(`parse::error::webpack-config::not-found received`);
await context.report('', null, 'webpack configuration file not found in your project.');
};
context.on('parse::webpack-config::error::not-found', notFound);
context.on('parse::error::webpack-config::not-found', notFound);
}
}
@@ -31,11 +31,11 @@ export default class WebpackConfigIsInstalled implements IHint {
public constructor(context: HintContext<WebpackConfigEvents>) {
const notInstall = async () => {
debug(`parse::webpack-config::error::not-install received`);
debug(`parse::error::webpack-config::not-install received`);
await context.report('', null, 'webpack is not installed in your project.');
};
context.on('parse::webpack-config::error::not-install', notInstall);
context.on('parse::error::webpack-config::not-install', notInstall);
}
}
@@ -33,11 +33,11 @@ export default class WebpackConfigIsValid implements IHint {
const invalidConfigurationFile = async (webpackConfigInvalid: WebpackConfigInvalidConfiguration) => {
const { error, resource } = webpackConfigInvalid;
debug(`parse::webpack-config::error::configuration received`);
debug(`parse::error::webpack-config::configuration received`);
await context.report(resource, null, error.message);
};
context.on('parse::webpack-config::error::configuration', invalidConfigurationFile);
context.on('parse::error::webpack-config::configuration', invalidConfigurationFile);
}
}
@@ -7,10 +7,8 @@ import { HintContext } from 'hint/dist/src/lib/hint-context';
import { IHint, HintMetadata } from 'hint/dist/src/lib/types';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
/* eslint-disable no-unused-vars */
import { WebpackConfigEvents, WebpackConfigParse } from '@hint/parser-webpack-config';
import { TypeScriptConfigEvents, TypeScriptConfigParse } from '@hint/parser-typescript-config';
/* eslint-enable no-unused-vars*/
const debug: debug.IDebugger = d(__filename);
@@ -37,13 +35,13 @@ export default class WebpackConfigModuleESNextTypescript implements IHint {
let typescriptEvent: TypeScriptConfigParse;
const webpackConfigReceived = (webpackConfigEvent: WebpackConfigParse) => {
debug(`parse::webpack-config::end received`);
debug(`parse::end::webpack-config received`);
webpackEvent = webpackConfigEvent;
};
const typescriptConfigReceived = (typescriptConfigEvent: TypeScriptConfigParse) => {
debug(`parse::typescript-config::end received`);
debug(`parse::end::typescript-config received`);
typescriptEvent = typescriptConfigEvent;
};
@@ -72,8 +70,8 @@ export default class WebpackConfigModuleESNextTypescript implements IHint {
}
};
context.on('parse::webpack-config::end', webpackConfigReceived);
context.on('parse::typescript-config::end', typescriptConfigReceived);
context.on('parse::end::webpack-config', webpackConfigReceived);
context.on('parse::end::typescript-config', typescriptConfigReceived);
context.on('scan::end', validate);
}
}
@@ -7,10 +7,8 @@ import { HintContext } from 'hint/dist/src/lib/hint-context';
import { IHint, HintMetadata } from 'hint/dist/src/lib/types';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
/* eslint-disable no-unused-vars */
import { WebpackConfigEvents, WebpackConfigParse } from '@hint/parser-webpack-config';
import { BabelConfigEvents, BabelConfigParsed } from '@hint/parser-babel-config';
/* eslint-enable no-unused-vars */
const debug: debug.IDebugger = d(__filename);
@@ -37,13 +35,13 @@ export default class WebpackConfigModulesFalseBabel implements IHint {
let babelEvent: BabelConfigParsed;
const webpackConfigReceived = (webpackConfigEvent: WebpackConfigParse) => {
debug(`parse::webpack-config::end received`);
debug(`parse::end::webpack-config received`);
webpackEvent = webpackConfigEvent;
};
const babelConfigReceived = (babelConfigEvent: BabelConfigParsed) => {
debug(`parse::babel-config::end received`);
debug(`parse::end::babel-config received`);
babelEvent = babelConfigEvent;
};
@@ -77,8 +75,8 @@ export default class WebpackConfigModulesFalseBabel implements IHint {
}
};
context.on('parse::webpack-config::end', webpackConfigReceived);
context.on('parse::babel-config::end', babelConfigReceived);
context.on('parse::end::webpack-config', webpackConfigReceived);
context.on('parse::end::babel-config', babelConfigReceived);
context.on('scan::end', validate);
}
}
@@ -33,13 +33,13 @@ export default class WebpackConfigNoDevtoolInProd implements IHint {
const configReceived = async (webpackConfigEvent: WebpackConfigParse) => {
const { config, resource } = webpackConfigEvent;
debug(`parse::webpack-config::end received`);
debug(`parse::end::webpack-config received`);
if (config.devtool && config.devtool.toString().includes('eval')) {
await context.report(resource, null, `\`${config.devtool.toString()}\` not recommended for prodution`);
}
};
context.on('parse::webpack-config::end', configReceived);
context.on('parse::end::webpack-config', configReceived);
}
}
Oops, something went wrong.

0 comments on commit 8499d5c

Please sign in to comment.