From 99c250bebeb529e77e6472750b47caee98c0edd3 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 15 Dec 2017 15:29:41 +0100 Subject: [PATCH] update typescript and prettier, use shortcut fragment syntax (#2913) --- server/sonar-web/package.json | 6 ++-- server/sonar-web/src/main/js/api/plugins.ts | 14 ++++----- .../js/app/components/ComponentContainer.tsx | 30 +++++++++---------- .../components/nav/component/ComponentNav.tsx | 20 ++++++------- .../src/main/js/app/utils/startReactApp.js | 3 +- .../organizations/OrganizationsList.js | 14 ++++----- .../js/apps/code/components/Component.tsx | 4 +-- .../apps/code/components/ComponentsHeader.tsx | 4 +-- .../src/main/js/apps/marketplace/App.tsx | 22 +++++++------- .../apps/projectActivity/components/Event.js | 6 ++-- .../apps/projects/components/PageSidebar.tsx | 8 ++--- .../components/ProjectsSortingSelect.tsx | 15 +++++----- .../changelog/__tests__/Changelog-test.tsx | 3 +- .../compare/ComparisonResults.tsx | 12 ++++---- .../details/ProfilePermissionsForm.tsx | 10 ++----- .../components/LoginFormContainer.tsx | 21 +++++++------ .../js/apps/users/components/UserActions.tsx | 4 +-- .../sonar-web/src/main/js/helpers/request.ts | 2 +- server/sonar-web/tsconfig.json | 1 + server/sonar-web/yarn.lock | 18 +++++------ 20 files changed, 105 insertions(+), 112 deletions(-) diff --git a/server/sonar-web/package.json b/server/sonar-web/package.json index 1610cd1f0bf..43c73375f6c 100644 --- a/server/sonar-web/package.json +++ b/server/sonar-web/package.json @@ -96,14 +96,14 @@ "postcss-calc": "6.0.1", "postcss-custom-properties": "6.2.0", "postcss-loader": "2.0.8", - "prettier": "1.7.4", + "prettier": "1.9.2", "react-error-overlay": "1.0.7", "react-test-renderer": "16.2.0", "rimraf": "2.6.2", "style-loader": "0.19.0", "ts-jest": "21.1.4", - "typescript": "2.5.3", - "typescript-eslint-parser": "8.0.1", + "typescript": "2.6.2", + "typescript-eslint-parser": "11.0.0", "webpack": "3.8.1", "webpack-bundle-analyzer": "2.9.0", "webpack-dev-server": "2.9.3" diff --git a/server/sonar-web/src/main/js/api/plugins.ts b/server/sonar-web/src/main/js/api/plugins.ts index a8ea293b1e6..2579825b9ac 100644 --- a/server/sonar-web/src/main/js/api/plugins.ts +++ b/server/sonar-web/src/main/js/api/plugins.ts @@ -86,14 +86,12 @@ function getLastUpdates(updates: undefined | Update[]): Update[] { if (!updates) { return []; } - const lastUpdate = [ - 'COMPATIBLE', - 'REQUIRES_SYSTEM_UPGRADE', - 'DEPS_REQUIRE_SYSTEM_UPGRADE' - ].map(status => { - const index = findLastIndex(updates, update => update.status === status); - return index > -1 ? updates[index] : undefined; - }); + const lastUpdate = ['COMPATIBLE', 'REQUIRES_SYSTEM_UPGRADE', 'DEPS_REQUIRE_SYSTEM_UPGRADE'].map( + status => { + const index = findLastIndex(updates, update => update.status === status); + return index > -1 ? updates[index] : undefined; + } + ); return lastUpdate.filter(Boolean) as Update[]; } diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx index f790ab376fe..eb02ba1d579 100644 --- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx @@ -89,26 +89,26 @@ export class ComponentContainer extends React.PureComponent { } }; - Promise.all([ - getComponentNavigation(id, branch), - getComponentData(id, branch) - ]).then(([nav, data]) => { - const component = this.addQualifier({ ...nav, ...data }); - - if (this.props.organizationsEnabled) { - this.props.fetchOrganizations([component.organization]); - } + Promise.all([getComponentNavigation(id, branch), getComponentData(id, branch)]).then( + ([nav, data]) => { + const component = this.addQualifier({ ...nav, ...data }); - this.fetchBranches(component).then(branches => { - if (this.mounted) { - this.setState({ loading: false, branches, component }); + if (this.props.organizationsEnabled) { + this.props.fetchOrganizations([component.organization]); } - }, onError); - }, onError); + + this.fetchBranches(component).then(branches => { + if (this.mounted) { + this.setState({ loading: false, branches, component }); + } + }, onError); + }, + onError + ); } fetchBranches = (component: Component) => { - const project = component.breadcrumbs.find((c: Component) => c.qualifier === 'TRK'); + const project = component.breadcrumbs.find(({ qualifier }) => qualifier === 'TRK'); return project ? getBranches(project.key) : Promise.resolve([]); }; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx index 8f13a285693..2dbc6fe9ea4 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx @@ -68,17 +68,17 @@ export default class ComponentNav extends React.PureComponent { } loadStatus = () => { - getTasksForComponent( - this.props.component.key - ).then((r: { queue: PendingTask[]; current: Task }) => { - if (this.mounted) { - this.setState({ - currentTask: r.current, - isInProgress: r.queue.some(task => task.status === STATUSES.IN_PROGRESS), - isPending: r.queue.some(task => task.status === STATUSES.PENDING) - }); + getTasksForComponent(this.props.component.key).then( + (r: { queue: PendingTask[]; current: Task }) => { + if (this.mounted) { + this.setState({ + currentTask: r.current, + isInProgress: r.queue.some(task => task.status === STATUSES.IN_PROGRESS), + isPending: r.queue.some(task => task.status === STATUSES.PENDING) + }); + } } - }); + ); }; populateRecentHistory = () => { diff --git a/server/sonar-web/src/main/js/app/utils/startReactApp.js b/server/sonar-web/src/main/js/app/utils/startReactApp.js index 0040ae22fa8..8866517ccab 100644 --- a/server/sonar-web/src/main/js/app/utils/startReactApp.js +++ b/server/sonar-web/src/main/js/app/utils/startReactApp.js @@ -185,7 +185,8 @@ const startReactApp = () => { - import('../components/ComponentContainer').then(i => i.default)}> + import('../components/ComponentContainer').then(i => i.default) + }> diff --git a/server/sonar-web/src/main/js/apps/account/organizations/OrganizationsList.js b/server/sonar-web/src/main/js/apps/account/organizations/OrganizationsList.js index 621f1b59117..921b636dd3a 100644 --- a/server/sonar-web/src/main/js/apps/account/organizations/OrganizationsList.js +++ b/server/sonar-web/src/main/js/apps/account/organizations/OrganizationsList.js @@ -32,13 +32,13 @@ type Props = { export default function OrganizationsList(props /*: Props */) { return (
    - {sortBy(props.organizations, organization => - organization.name.toLocaleLowerCase() - ).map(organization => ( -
  • - -
  • - ))} + {sortBy(props.organizations, organization => organization.name.toLocaleLowerCase()).map( + organization => ( +
  • + +
  • + ) + )}
); } diff --git a/server/sonar-web/src/main/js/apps/code/components/Component.tsx b/server/sonar-web/src/main/js/apps/code/components/Component.tsx index 8412774fc27..f4198dcc060 100644 --- a/server/sonar-web/src/main/js/apps/code/components/Component.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/Component.tsx @@ -102,7 +102,7 @@ export default class Component extends React.PureComponent { { metric: 'sqale_rating', type: 'RATING' }, { metric: 'ncloc', type: 'SHORT_INT' } ] - : [ + : ([ isApplication && { metric: 'alert_status', type: 'LEVEL' }, { metric: 'ncloc', type: 'SHORT_INT' }, { metric: 'bugs', type: 'SHORT_INT' }, @@ -110,7 +110,7 @@ export default class Component extends React.PureComponent { { metric: 'code_smells', type: 'SHORT_INT' }, { metric: 'coverage', type: 'PERCENT' }, { metric: 'duplicated_lines_density', type: 'PERCENT' } - ].filter(Boolean) as Array<{ metric: string; type: string }>; + ].filter(Boolean) as Array<{ metric: string; type: string }>); return ( (this.node = node as HTMLElement)}> diff --git a/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx b/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx index a2138a020b4..69590a84ce5 100644 --- a/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/ComponentsHeader.tsx @@ -38,7 +38,7 @@ export default function ComponentsHeader({ baseComponent, rootComponent }: Props translate('metric_domain.Maintainability'), translate('metric', 'ncloc', 'name') ] - : [ + : ([ isApplication && translate('metric.alert_status.name'), translate('metric', 'ncloc', 'name'), translate('metric', 'bugs', 'name'), @@ -46,7 +46,7 @@ export default function ComponentsHeader({ baseComponent, rootComponent }: Props translate('metric', 'code_smells', 'name'), translate('metric', 'coverage', 'name'), translate('metric', 'duplicated_lines_density', 'short_name') - ].filter(Boolean) as string[]; + ].filter(Boolean) as string[]); return ( diff --git a/server/sonar-web/src/main/js/apps/marketplace/App.tsx b/server/sonar-web/src/main/js/apps/marketplace/App.tsx index 6ee7fd37bbc..41868176456 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/App.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/App.tsx @@ -109,17 +109,17 @@ export default class App extends React.PureComponent { fetchAllPlugins = () => { this.setState({ loadingPlugins: true }); - Promise.all([ - getInstalledPluginsWithUpdates(), - getAvailablePlugins() - ]).then(([installed, available]) => { - if (this.mounted) { - this.setState({ - loadingPlugins: false, - plugins: sortBy(uniqBy([...installed, ...available.plugins], 'key'), 'name') - }); - } - }, this.stopLoadingPlugins); + Promise.all([getInstalledPluginsWithUpdates(), getAvailablePlugins()]).then( + ([installed, available]) => { + if (this.mounted) { + this.setState({ + loadingPlugins: false, + plugins: sortBy(uniqBy([...installed, ...available.plugins], 'key'), 'name') + }); + } + }, + this.stopLoadingPlugins + ); }; fetchUpdatesOnly = () => { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/Event.js b/server/sonar-web/src/main/js/apps/projectActivity/components/Event.js index 8cec8967717..182fb442459 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/Event.js +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/Event.js @@ -122,9 +122,9 @@ export default class Event extends React.PureComponent { removeEventButtonText={ 'project_activity.' + (isVersion ? 'remove_version' : 'remove_custom_event') } - removeEventQuestion={`project_activity.${isVersion - ? 'remove_version' - : 'remove_custom_event'}.question`} + removeEventQuestion={`project_activity.${ + isVersion ? 'remove_version' : 'remove_custom_event' + }.question`} /> )} diff --git a/server/sonar-web/src/main/js/apps/projects/components/PageSidebar.tsx b/server/sonar-web/src/main/js/apps/projects/components/PageSidebar.tsx index d22864bc006..d45257e1984 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/PageSidebar.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/PageSidebar.tsx @@ -82,7 +82,7 @@ export default function PageSidebar(props: Props) { {!isLeakView && ( - + <> - + )} {isLeakView && ( - + <> - + )} { getOptions = () => { const sortMetrics = this.props.view === 'leak' ? SORTING_LEAK_METRICS : SORTING_METRICS; - return sortBy( - sortMetrics, - option => (option.value === this.props.defaultOption ? 0 : 1) - ).map(option => ({ - value: option.value, - label: translate('projects.sorting', option.value), - class: option.class - })); + return sortBy(sortMetrics, option => (option.value === this.props.defaultOption ? 0 : 1)).map( + option => ({ + value: option.value, + label: translate('projects.sorting', option.value), + class: option.class + }) + ); }; handleDescToggle = () => { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.tsx index 6272bcc2f12..66c06ac5e9a 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/Changelog-test.tsx @@ -23,7 +23,7 @@ import Changelog from '../Changelog'; import ChangesList from '../ChangesList'; import { ProfileChangelogEvent } from '../../types'; -function createEvent(overrides?: { [p: string]: any }): ProfileChangelogEvent { +function createEvent(overrides?: Partial): ProfileChangelogEvent { return { date: '2016-01-01', authorName: 'John', @@ -31,7 +31,6 @@ function createEvent(overrides?: { [p: string]: any }): ProfileChangelogEvent { ruleKey: 'squid1234', ruleName: 'Do not do this', params: {}, - organization: null, ...overrides }; } diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResults.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResults.tsx index a98f0e91b5f..1ba6f4fd5eb 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResults.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/compare/ComparisonResults.tsx @@ -74,7 +74,7 @@ export default class ComparisonResults extends React.PureComponent { return null; } return ( - + <>
@@ -93,7 +93,7 @@ export default class ComparisonResults extends React.PureComponent {   ))} - + ); } @@ -102,7 +102,7 @@ export default class ComparisonResults extends React.PureComponent { return null; } return ( - + <>   @@ -121,7 +121,7 @@ export default class ComparisonResults extends React.PureComponent { {this.renderRule(rule, rule.severity)} ))} - + ); } @@ -130,7 +130,7 @@ export default class ComparisonResults extends React.PureComponent { return null; } return ( - + <>
@@ -161,7 +161,7 @@ export default class ComparisonResults extends React.PureComponent { ))} - + ); } diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx index 0732a1f0783..ba788305e51 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfilePermissionsForm.tsx @@ -99,13 +99,9 @@ export default class ProfilePermissionsForm extends React.PureComponent [ - ...usersResponse.users, - ...groupsResponse.groups - ]); + return Promise.all([searchUsers(parameters), searchGroups(parameters)]).then( + ([usersResponse, groupsResponse]) => [...usersResponse.users, ...groupsResponse.groups] + ); }; handleValueChange = (selected: User | Group) => { diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx index f4096338e9a..71fff3c8330 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx @@ -41,18 +41,17 @@ class LoginFormContainer extends React.PureComponent { componentDidMount() { this.mounted = true; - Promise.all([ - getIdentityProviders(), - tryGetGlobalNavigation() - ]).then(([identityProvidersResponse, appState]) => { - if (this.mounted) { - this.setState({ - onSonarCloud: - appState.settings && appState.settings['sonar.sonarcloud.enabled'] === 'true', - identityProviders: identityProvidersResponse.identityProviders - }); + Promise.all([getIdentityProviders(), tryGetGlobalNavigation()]).then( + ([identityProvidersResponse, appState]) => { + if (this.mounted) { + this.setState({ + onSonarCloud: + appState.settings && appState.settings['sonar.sonarcloud.enabled'] === 'true', + identityProviders: identityProvidersResponse.identityProviders + }); + } } - }); + ); } componentWillUnmount() { diff --git a/server/sonar-web/src/main/js/apps/users/components/UserActions.tsx b/server/sonar-web/src/main/js/apps/users/components/UserActions.tsx index 4d3302709f0..ac2710c00d7 100644 --- a/server/sonar-web/src/main/js/apps/users/components/UserActions.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/UserActions.tsx @@ -76,7 +76,7 @@ export default class UserActions extends React.PureComponent { const { isCurrentUser, onUpdateUsers, user } = this.props; return ( - + <> {this.renderActions()} {openForm === 'deactivate' && ( { {openForm === 'update' && ( )} - + ); } } diff --git a/server/sonar-web/src/main/js/helpers/request.ts b/server/sonar-web/src/main/js/helpers/request.ts index 3aa3a90248c..0164bb2ed10 100644 --- a/server/sonar-web/src/main/js/helpers/request.ts +++ b/server/sonar-web/src/main/js/helpers/request.ts @@ -167,7 +167,7 @@ export function parseJSON(response: Response): Promise { return response.json(); } -/** +/** * Parse response of failed request */ export function parseError(error: { response: Response }): Promise { diff --git a/server/sonar-web/tsconfig.json b/server/sonar-web/tsconfig.json index 427192d12e7..a99673585de 100644 --- a/server/sonar-web/tsconfig.json +++ b/server/sonar-web/tsconfig.json @@ -6,6 +6,7 @@ "noUnusedParameters": true, "noImplicitAny": true, "strict": true, + "strictFunctionTypes": false, "target": "es5", "jsx": "react", "lib": ["es2017", "dom"], diff --git a/server/sonar-web/yarn.lock b/server/sonar-web/yarn.lock index 79a4fa67c81..86da451ace2 100644 --- a/server/sonar-web/yarn.lock +++ b/server/sonar-web/yarn.lock @@ -5837,9 +5837,9 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.7.4: - version "1.7.4" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.4.tgz#5e8624ae9363c80f95ec644584ecdf55d74f93fa" +prettier@1.9.2: + version "1.9.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.2.tgz#96bc2132f7a32338e6078aeb29727178c6335827" pretty-error@^2.0.2: version "2.1.1" @@ -7305,16 +7305,16 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript-eslint-parser@8.0.1: - version "8.0.1" - resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-8.0.1.tgz#e8cac537d996e16c3dbb0d7c4d509799e67afe0c" +typescript-eslint-parser@11.0.0: + version "11.0.0" + resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-11.0.0.tgz#37dba6a0130dd307504aa4b4b21b0d3dc7d4e9f2" dependencies: lodash.unescape "4.0.1" semver "5.4.1" -typescript@2.5.3: - version "2.5.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d" +typescript@2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4" ua-parser-js@^0.7.9: version "0.7.17" -- 2.39.5