Skip to content

Commit

Permalink
fix(inspector): correct filepath cross-references in aggregate messag…
Browse files Browse the repository at this point in the history
…es; closes #18

- do not hardcode `spec` in `.mocharc.js`; it's impossible to execute a single test file if it's there
- add sourcemaps to Rollup config for debugging
- fix "way too many subscriptions" to `Observable<Report>` instances
- use `_.coerceToArray()` in a couple places
- put `NO_FILEPATH` and `MULTIPLE_FILEPATHS` constants where they should be
- import `gte` and `__` (placeholder) from `lodash/fp`
- sort _before_ instantiating the `Report` object, not after (it will be moved anyway; see #19)
- don't use hardcoded JSON in JSON formatter test
- add some debugs
- fix bad debug namespace in `rule-config.js`
- refactor some logic into a new `Message` class in the inspector
- rename `context` to `report` anywhere NOT in a Rule impl
- remove unused `createReportWithFilepath()`
- don't refuse to instantiate a `Report` from a `Report`
- actually create a `Report` when inspecting (test harness)
- remove dupe of `library-mismatch.spec.js`
  • Loading branch information
boneskull committed Jul 15, 2019
1 parent 645843f commit a707642
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 212 deletions.
3 changes: 1 addition & 2 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ module.exports = {
'experimental-report': true,
'forbid-only': Boolean(process.env.CI),
'no-warnings': true,
require: ['esm', require.resolve('./packages/common/test/setup.js')],
spec: './packages/*/test/**/*.spec.js'
require: ['esm', require.resolve('./packages/common/test/setup.js')]
};
233 changes: 233 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"lint": "eslint .",
"prerelease": "cross-env NPM_CONFIG_LOGLEVEL=silent npm run clean && npm run build",
"pretest": "cross-env NPM_CONFIG_LOGLEVEL=silent npm run build",
"test": "mocha",
"test": "mocha \"./packages/*/test/**/*.spec.js\"",
"posttest": "cross-env NPM_CONFIG_LOGLEVEL=silent npm run lint"
},
"husky": {
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {colors, fail, toFormattedString} from '../console-utils.js';
import {GROUPS, OPTIONS} from './common.js';

const {ERROR, INFO, WARNING} = constants;
const {fromAny} = observable;
const {fromAny, share} = observable;
const {toInspection, toReportFromObject, toRuleConfig} = stream;

const BUILTIN_RULES_DIR = join(
Expand All @@ -26,7 +26,7 @@ export const desc = 'Inspect diagnostic report JSON against rules';
export const builder = yargs =>
yargs
.positional('file', {
coerce: v => (_.isArray(v) ? v : [v]),
coerce: _.coerceToArray,
type: 'array'
})
.options({
Expand All @@ -53,7 +53,8 @@ export const handler = argv => {
} = argv;
const reports = fromAny(filepaths).pipe(
toObjectFromFilepath({...config.inspect}),
toReportFromObject({...config.inspect, showSecretsUnsafe})
toReportFromObject({...config.inspect, showSecretsUnsafe}),
share()
);
fromSearchpathToRuleDefinition(BUILTIN_RULES_DIR)
.pipe(
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const ERROR = 'error';
export const WARNING = 'warning';
export const INFO = 'info';
export const NAMESPACE = 'gnostic';
export const NO_FILEPATH = '(no filepath)';
export const MULTIPLE_FILEPATHS = '(multiple files)';

export const DEFAULT_DIFF_OPTIONS = Object.freeze({
properties: Object.freeze([
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import flip from 'lodash/fp/flip.js';
import forEach from 'lodash/fp/forEach.js';
import get from 'lodash/fp/get.js';
import getOr from 'lodash/fp/getOr.js';
import gte from 'lodash/fp/gte.js';
import has from 'lodash/fp/has.js';
import identity from 'lodash/fp/identity.js';
import includes from 'lodash/fp/includes.js';
Expand Down Expand Up @@ -40,6 +41,7 @@ import overEvery from 'lodash/fp/overEvery.js';
import overSome from 'lodash/fp/overSome.js';
import pick from 'lodash/fp/pick.js';
import pipe from 'lodash/fp/pipe.js';
import __ from 'lodash/fp/placeholder.js';
import reduce from 'lodash/fp/reduce.js';
import reverse from 'lodash/fp/reverse.js';
import size from 'lodash/fp/size.js';
Expand All @@ -57,6 +59,7 @@ import traverse from 'traverse';
export const coerceToArray = value => (isArray(value) ? value : [value]);

export const _ = {
__,
clamp,
concat,
constant,
Expand All @@ -70,6 +73,7 @@ export const _ = {
forEach,
get,
getOr,
gte,
has,
identity,
includes,
Expand Down
Loading

0 comments on commit a707642

Please sign in to comment.