FIX linting

This commit is contained in:
Norbert de Langen 2019-11-15 21:48:31 +01:00
parent bd4ac31ac4
commit e018f67690
33 changed files with 205 additions and 167 deletions

View File

@ -185,7 +185,4 @@ class HighlightToggle extends Component<ToggleProps> {
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(HighlightToggle);
export default connect(mapStateToProps, mapDispatchToProps)(HighlightToggle);

View File

@ -27,7 +27,10 @@ describe('Tests on addon-contexts component: ToolBar', () => {
icon: 'box' as const,
nodeId: 'Some Context B',
options: { cancelable: true, deep: false, disable: false },
params: [{ name: 'Some Param X', props: {} }, { name: 'Some Param Y', props: {} }],
params: [
{ name: 'Some Param X', props: {} },
{ name: 'Some Param Y', props: {} },
],
title: 'Some Context B',
},
];

View File

@ -9,7 +9,10 @@ describe('Tests on addon-contexts component: ToolBarControl', () => {
icon: 'box' as const,
nodeId: 'Some Context',
options: { cancelable: true, deep: false, disable: false },
params: [{ name: 'A', props: {} }, { name: 'B', props: {} }],
params: [
{ name: 'A', props: {} },
{ name: 'B', props: {} },
],
title: 'Some Context',
selected: '',
setSelected: jest.fn,

View File

@ -22,7 +22,10 @@ describe('Test on the merging result of a pair of settings', () => {
icon: 'box' as const,
title: 'Some Context',
components: ['div'],
params: [{ name: 'T1', props: {} }, { name: 'T2', props: {} }],
params: [
{ name: 'T1', props: {} },
{ name: 'T2', props: {} },
],
options: {
cancelable: true,
disable: true,
@ -32,7 +35,10 @@ describe('Test on the merging result of a pair of settings', () => {
icon: 'box' as const,
title: 'Some Context',
components: ['span'],
params: [{ name: 'S1', props: {} }, { name: 'S2', props: {} }],
params: [
{ name: 'S1', props: {} },
{ name: 'S2', props: {} },
],
options: {
deep: true,
disable: false,
@ -106,7 +112,10 @@ describe('Test on reconciliation of settings', () => {
icon: 'box',
nodeId: 'Some Context',
options: { cancelable: false, deep: false, disable: false },
params: [{ name: 'T1', props: {} }, { name: 'S2', props: {}, default: true }],
params: [
{ name: 'T1', props: {} },
{ name: 'S2', props: {}, default: true },
],
title: 'Some Context',
},
{

View File

@ -2,7 +2,10 @@ import { _getPropsByParamName, getPropsMap } from './getPropsMap';
import { OPT_OUT } from '../../shared/constants';
describe('Test on behaviors from collecting the propsMap', () => {
const someParams = [{ name: 'A', props: {} }, { name: 'B', props: {} }];
const someParams = [
{ name: 'A', props: {} },
{ name: 'B', props: {} },
];
it('should return "null" when params in 0 length', () => {
const result = _getPropsByParamName([]);
@ -44,7 +47,10 @@ describe('Test on the integrity of the method to get the propMaps', () => {
icon: 'box' as const,
nodeId: 'Some Context',
options: { cancelable: false, deep: false, disable: false },
params: [{ name: 'A1', props: { a: 1 } }, { name: 'A2', props: { a: 2 }, default: true }],
params: [
{ name: 'A1', props: { a: 1 } },
{ name: 'A2', props: { a: 2 }, default: true },
],
title: 'Some Context',
},
{

View File

@ -31,14 +31,6 @@ jest.mock('global', () => ({
},
}));
export const mockChannel = () => {
return {
emit: jest.fn(),
on: jest.fn(),
once: jest.fn(),
};
};
describe('preview', () => {
describe('linkTo()', () => {
it('should select the kind and story provided', () => {
@ -116,7 +108,10 @@ describe('preview', () => {
addons.getChannel.mockReturnValue(channel);
__STORYBOOK_STORY_STORE__.fromId.mockImplementation(input => null);
const handler = linkTo((a, b) => a + b, (a, b) => b + a);
const handler = linkTo(
(a, b) => a + b,
(a, b) => b + a
);
handler('kind', 'name');
expect(channel.emit.mock.calls).toContainEqual([

View File

@ -3,11 +3,18 @@ import React from 'react';
import addons from '@storybook/addons';
import { SELECT_STORY } from '@storybook/core-events';
import { mockChannel } from '../../preview.test';
import LinkTo from './link';
jest.mock('@storybook/addons');
const mockChannel = () => {
return {
emit: jest.fn(),
on: jest.fn(),
once: jest.fn(),
};
};
describe('LinkTo', () => {
describe('render', () => {
it('should render a link', async () => {

View File

@ -1,3 +1,4 @@
/* eslint-disable jest/no-export */
import fs from 'fs';
import glob from 'glob';
import { describe, it } from 'global';

View File

@ -1,3 +1,5 @@
/* eslint-disable jest/no-export */
/* eslint-disable jest/expect-expect */
import { describe, it } from 'global';
import { addSerializer } from 'jest-specific-snapshot';
@ -6,13 +8,17 @@ function snapshotTest({ item, asyncJest, framework, testMethod, testMethodParams
const context = { ...item, framework };
if (asyncJest === true) {
it(name, (done: jest.DoneCallback) =>
testMethod({
done,
story: item,
context,
...testMethodParams,
})
it(
name,
() =>
new Promise(done =>
testMethod({
done,
story: item,
context,
...testMethodParams,
})
)
);
} else {
it(name, () =>
@ -27,9 +33,7 @@ function snapshotTest({ item, asyncJest, framework, testMethod, testMethodParams
function snapshotTestSuite({ item, suite, ...restParams }: any) {
const { kind, children } = item;
// eslint-disable-next-line jest/valid-describe
describe(suite, () => {
// eslint-disable-next-line jest/valid-describe
describe(kind, () => {
children.forEach((c: any) => {
snapshotTest({ item: c, ...restParams });

View File

@ -13,16 +13,13 @@ function getLoaders(): Loader[] {
.readdirSync(__dirname)
.map(name => path.join(__dirname, name))
.filter(isDirectory)
.reduce(
(acc, framework) => {
const filename = path.join(framework, loaderScriptName);
const jsFile = `${filename}.js`;
const tsFile = `${filename}.ts`;
.reduce((acc, framework) => {
const filename = path.join(framework, loaderScriptName);
const jsFile = `${filename}.js`;
const tsFile = `${filename}.ts`;
return acc.concat([jsFile, tsFile]);
},
[] as string[]
)
return acc.concat([jsFile, tsFile]);
}, [] as string[])
.filter(fs.existsSync)
.map(loader => require(loader).default);
}

View File

@ -77,7 +77,7 @@ export class AppComponent implements OnInit, OnDestroy {
const value = props[key];
const instanceProperty = instance[key];
if (!(instanceProperty instanceof EventEmitter) && (value !== undefined && value !== null)) {
if (!(instanceProperty instanceof EventEmitter) && value !== undefined && value !== null) {
// eslint-disable-next-line no-param-reassign
instance[key] = value;
if (hasNgOnChangesHook) {

View File

@ -2,7 +2,7 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import getTsLoaderOptions from '../ts_config';
import createForkTsCheckerInstance from '../create-fork-ts-checker-plugin';
// eslint-disable-next-line global-require
// eslint-disable-next-line global-require, jest/no-mocks-import
jest.mock('fs', () => require('../../../../../__mocks__/fs'));
jest.mock('path', () => ({
resolve: () => 'tsconfig.json',

View File

@ -1,6 +1,6 @@
import getTsLoaderOptions from '../ts_config';
// eslint-disable-next-line global-require
// eslint-disable-next-line global-require, jest/no-mocks-import
jest.mock('fs', () => require('../../../../../__mocks__/fs'));
jest.mock('path', () => ({
resolve: () => 'tsconfig.json',

View File

@ -1,3 +1,4 @@
/* eslint-disable jest/no-mocks-import */
import fs from 'fs';
import path from 'path';
import {

View File

@ -71,29 +71,26 @@ export function isReactScriptsInstalled(requiredVersion = '2.0.0') {
}
export const getRules = (extensions: string[]) => (rules: RuleSetRule[]) =>
rules.reduce(
(craRules, rule) => {
// If at least one extension satisfies the rule test, the rule is one
// we want to extract
if (rule.test && extensions.some(normalizeCondition(rule.test))) {
// If the base test is for extensions, return early
return craRules.concat(rule);
}
rules.reduce((craRules, rule) => {
// If at least one extension satisfies the rule test, the rule is one
// we want to extract
if (rule.test && extensions.some(normalizeCondition(rule.test))) {
// If the base test is for extensions, return early
return craRules.concat(rule);
}
// Get any rules contained in rule.oneOf
if (!rule.test && rule.oneOf) {
craRules.push(...getRules(extensions)(rule.oneOf));
}
// Get any rules contained in rule.oneOf
if (!rule.test && rule.oneOf) {
craRules.push(...getRules(extensions)(rule.oneOf));
}
// Get any rules contained in rule.rules
if (!rule.test && rule.rules) {
craRules.push(...getRules(extensions)(rule.rules));
}
// Get any rules contained in rule.rules
if (!rule.test && rule.rules) {
craRules.push(...getRules(extensions)(rule.rules));
}
return craRules;
},
[] as RuleSetRule[]
);
return craRules;
}, [] as RuleSetRule[]);
const getStyleRules = getRules(cssExtensions.concat(cssModuleExtensions));
@ -101,23 +98,20 @@ export const getTypeScriptRules = (webpackConfigRules: RuleSetRule[], configDir:
const rules = getRules(typeScriptExtensions)(webpackConfigRules);
// Adds support for using TypeScript in the `.storybook` (or config) folder.
return rules.reduce(
(accRules, rule) => {
// Resolves an issue where this config is parsed twice (#4903).
if (typeof rule.include !== 'string') {
return [...accRules, rule];
}
return rules.reduce((accRules, rule) => {
// Resolves an issue where this config is parsed twice (#4903).
if (typeof rule.include !== 'string') {
return [...accRules, rule];
}
return [
...accRules,
{
...rule,
include: [rule.include, path.resolve(configDir)],
},
];
},
[] as RuleSetRule[]
);
return [
...accRules,
{
...rule,
include: [rule.include, path.resolve(configDir)],
},
];
}, [] as RuleSetRule[]);
};
export const getModulePath = () => {

View File

@ -1,5 +1,4 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable jest/valid-expect */
/* eslint-disable jest/no-standalone-expect, no-unused-expressions, jest/valid-expect */
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite

View File

@ -32,7 +32,10 @@ storiesOf('basics/tooltip/TooltipMessage', module)
<TooltipMessage
title="Lorem ipsum dolor sit"
desc="Amet consectatur vestibulum concet durum politu coret weirom"
links={[{ title: 'Get more tips', href: 'test' }, { title: 'Done', href: 'test' }]}
links={[
{ title: 'Get more tips', href: 'test' },
{ title: 'Done', href: 'test' },
]}
/>
))
.add('minimal message', () => (

View File

@ -128,6 +128,5 @@ interface TypeScriptHtmlComponentProps {
text: string;
}
export const TypeScriptHtmlComponent: FC<
React.HTMLAttributes<HTMLDivElement> & TypeScriptHtmlComponentProps
> = () => <div>My HTML component</div>;
export const TypeScriptHtmlComponent: FC<React.HTMLAttributes<HTMLDivElement> &
TypeScriptHtmlComponentProps> = () => <div>My HTML component</div>;

View File

@ -31,9 +31,10 @@ export const story5 = () =>
story5.story = { name: 'Multiple actions, selector' };
export const story6 = () =>
withActions({ click: 'clicked', contextmenu: 'right clicked' }, { clearOnStoryChange: false })(
button
);
withActions(
{ click: 'clicked', contextmenu: 'right clicked' },
{ clearOnStoryChange: false }
)(button);
story6.story = { name: 'Multiple actions, object + config' };
export const story7 = () => pickTarget.withActions('click', 'contextmenu')(button);

View File

@ -11,18 +11,20 @@ describe('Button Component', () => {
component = new Button.default({ target }); // eslint-disable-line new-cap
});
it('should render `text` property', done => {
const text = 'Hello world';
const expected = `Round corners ${text}`;
it('should render `text` property', () => {
return new Promise(done => {
const text = 'Hello world';
const expected = `Round corners ${text}`;
component.$on('afterUpdate', () => {
const componentText = target.firstChild.textContent.trim();
component.$on('afterUpdate', () => {
const componentText = target.firstChild.textContent.trim();
expect(componentText).toEqual(expected);
expect(componentText).toEqual(expected);
done();
done();
});
component.$set({ text });
});
component.$set({ text });
});
});

View File

@ -34,9 +34,10 @@ export const story5 = () =>
story5.story = { name: 'Multiple actions, selector' };
export const story6 = () =>
withActions({ click: 'clicked', contextmenu: 'right clicked' }, { clearOnStoryChange: false })(
button
);
withActions(
{ click: 'clicked', contextmenu: 'right clicked' },
{ clearOnStoryChange: false }
)(button);
story6.story = { name: 'Multiple actions, object + config' };
export const story7 = () => pickTarget.withActions('click', 'contextmenu')(button);

View File

@ -22,7 +22,10 @@ export const FrontOwnHeader = () => html`
export const BackWithData = () => html`
<demo-wc-card
back-side
.rows=${[{ header: 'health', value: '200' }, { header: 'mana', value: '100' }]}
.rows=${[
{ header: 'health', value: '200' },
{ header: 'mana', value: '100' },
]}
>
A simple card
</demo-wc-card>

View File

@ -5,7 +5,7 @@ import { makeDecorator } from './make-decorator';
// Copy & paste from internal api: client-api/src/client_api
type DecoratorFn = (fn: StoryGetter, context: StoryContext) => any;
export const defaultDecorateStory = (getStory: StoryGetter, decorators: DecoratorFn[]) =>
const defaultDecorateStory = (getStory: StoryGetter, decorators: DecoratorFn[]) =>
decorators.reduce(
(decorated, decorator) => (context: StoryContext) =>
decorator(() => decorated(context), context),

View File

@ -255,35 +255,32 @@ const initStoriesApi = ({
.concat(groups)
.map(toGroup)
// Map a bunch of extra fields onto the groups, collecting the path as we go (thus the reduce)
.reduce(
(soFar, group, index, original) => {
const { name } = group;
const parent = index > 0 && soFar[index - 1].id;
const id = sanitize(parent ? `${parent}-${name}` : name);
if (parent === id) {
throw new Error(
`
.reduce((soFar, group, index, original) => {
const { name } = group;
const parent = index > 0 && soFar[index - 1].id;
const id = sanitize(parent ? `${parent}-${name}` : name);
if (parent === id) {
throw new Error(
`
Invalid part '${name}', leading to id === parentId ('${id}'), inside kind '${kind}'
Did you create a path that uses the separator char accidentally, such as 'Vue <docs/>' where '/' is a separator char? See https://github.com/storybookjs/storybook/issues/6128
`.trim()
);
}
);
}
const result: Group = {
...group,
id,
parent,
depth: index,
children: [],
isComponent: index === original.length - 1,
isLeaf: false,
isRoot: !!root && index === 0,
};
return soFar.concat([result]);
},
[] as GroupsList
);
const result: Group = {
...group,
id,
parent,
depth: index,
children: [],
isComponent: index === original.length - 1,
isLeaf: false,
isRoot: !!root && index === 0,
};
return soFar.concat([result]);
}, [] as GroupsList);
const paths = [...rootAndGroups.map(g => g.id), item.id];

View File

@ -4,7 +4,7 @@ import ClientApi from './client_api';
import ConfigApi from './config_api';
import StoryStore from './story_store';
export const getContext = (() => decorateStory => {
const getContext = (() => decorateStory => {
const channel = mockChannel();
addons.setChannel(channel);
const storyStore = new StoryStore({ channel });

View File

@ -443,7 +443,11 @@ describe('Preview hooks', () => {
it('calculates initial state', () => {
let state;
const storyFn = () => {
[state] = useReducer(() => 'bar', 'foo', arg => arg);
[state] = useReducer(
() => 'bar',
'foo',
arg => arg
);
};
run(storyFn);
expect(state).toBe('foo');

View File

@ -11,7 +11,6 @@ const inputRegExp = /\.input\.js$/;
const fixturesDir = path.resolve(__dirname, '../__testfixtures__');
fs.readdirSync(fixturesDir).forEach(transformName => {
const transformFixturesDir = path.join(fixturesDir, transformName);
// eslint-disable-next-line jest/valid-describe
describe(transformName, () =>
fs
.readdirSync(transformFixturesDir)

View File

@ -157,8 +157,10 @@ export default function transformer(file, api) {
const { left } = exp.node;
return (
left.type === 'MemberExpression' &&
(left.object.type === 'Identifier' && left.object.name in storyKeyToStory) &&
(left.property.type === 'Identifier' && left.property.name === 'story')
left.object.type === 'Identifier' &&
left.object.name in storyKeyToStory &&
left.property.type === 'Identifier' &&
left.property.name === 'story'
);
});
storyAssignments.forEach(exp => {

View File

@ -2,7 +2,10 @@ export default function transformer(file, api) {
const j = api.jscodeshift;
const createImportDeclaration = (specifiers, source) =>
j.importDeclaration(specifiers.map(s => j.importSpecifier(j.identifier(s))), j.literal(source));
j.importDeclaration(
specifiers.map(s => j.importSpecifier(j.identifier(s))),
j.literal(source)
);
const deprecates = {
action: [['action'], '@storybook/addon-actions'],

View File

@ -29,7 +29,10 @@ storiesOf('basics/Tooltip/TooltipMessage', module)
<TooltipMessage
title="Lorem ipsum dolor sit"
desc="Amet consectatur vestibulum concet durum politu coret weirom"
links={[{ title: 'Get more tips', href: 'test' }, { title: 'Done', href: 'test' }]}
links={[
{ title: 'Get more tips', href: 'test' },
{ title: 'Done', href: 'test' },
]}
/>
))
.add('minimal message', () => (

View File

@ -100,11 +100,9 @@ WithTooltipPure.defaultProps = {
tooltipShown: false,
};
const WithToolTipState: FunctionComponent<
WithTooltipPureProps & {
startOpen?: boolean;
}
> = ({ startOpen, ...rest }) => {
const WithToolTipState: FunctionComponent<WithTooltipPureProps & {
startOpen?: boolean;
}> = ({ startOpen, ...rest }) => {
const [tooltipShown, onVisibilityChange] = useState(startOpen || false);
useEffect(() => {

View File

@ -11,7 +11,6 @@ const inputRegExp = /\.input\.js$/;
const fixturesDir = path.resolve(__dirname, './__testfixtures__');
fs.readdirSync(fixturesDir).forEach(transformName => {
const transformFixturesDir = path.join(fixturesDir, transformName);
// eslint-disable-next-line jest/valid-describe
describe(transformName, () =>
fs
.readdirSync(transformFixturesDir)

View File

@ -74,36 +74,44 @@ const Head = styled.div({
justifyContent: 'space-between',
});
const Brand = withTheme(({ theme: { brand: { title = 'Storybook', url = './', image } } }) => {
const targetValue = url === './' ? '' : '_blank';
if (image === undefined && url === null) {
return <Logo alt={title} />;
const Brand = withTheme(
({
theme: {
brand: { title = 'Storybook', url = './', image },
},
}) => {
const targetValue = url === './' ? '' : '_blank';
if (image === undefined && url === null) {
return <Logo alt={title} />;
}
if (image === undefined && url) {
return (
<LogoLink href={url} target={targetValue}>
<Logo alt={title} />
</LogoLink>
);
}
if (image === null && url === null) {
return title;
}
if (image === null && url) {
return (
<LogoLink href={url} target={targetValue} dangerouslySetInnerHTML={{ __html: title }} />
);
}
if (image && url === null) {
return <Img src={image} alt={title} />;
}
if (image && url) {
return (
<LogoLink href={url} target={targetValue}>
<Img src={image} alt={title} />
</LogoLink>
);
}
return null;
}
if (image === undefined && url) {
return (
<LogoLink href={url} target={targetValue}>
<Logo alt={title} />
</LogoLink>
);
}
if (image === null && url === null) {
return title;
}
if (image === null && url) {
return <LogoLink href={url} target={targetValue} dangerouslySetInnerHTML={{ __html: title }} />;
}
if (image && url === null) {
return <Img src={image} alt={title} />;
}
if (image && url) {
return (
<LogoLink href={url} target={targetValue}>
<Img src={image} alt={title} />
</LogoLink>
);
}
return null;
});
);
export interface SidebarHeadingProps {
menuHighlighted?: boolean;