Przeglądaj źródła

Merge pull request #730 from smiclea/apply-code-style

Apply the new code style changes to root files
Daniel Vincze 3 lat temu
rodzic
commit
fad003d44e
6 zmienionych plików z 140 dodań i 124 usunięć
  1. 24 15
      babel.config.js
  2. 63 56
      config.ts
  3. 10 13
      jest.config.ts
  4. 28 27
      webpack.common.js
  5. 9 8
      webpack.dev.js
  6. 6 5
      webpack.prod.js

+ 24 - 15
babel.config.js

@@ -1,30 +1,39 @@
 module.exports = api => {
-  api.cache.using(() => process.env.NODE_ENV)
+  api.cache.using(() => process.env.NODE_ENV);
 
   const common = {
     presets: [
-      ['@babel/env', { targets: { node: 'current' } }],
-      '@babel/typescript',
-      '@babel/react',
+      ["@babel/env", { targets: { node: "current" } }],
+      "@babel/typescript",
+      "@babel/react",
     ],
     plugins: [
-      'react-hot-loader/babel',
+      "react-hot-loader/babel",
       [
-        '@babel/plugin-proposal-decorators',
+        "@babel/plugin-proposal-decorators",
         {
           legacy: true,
         },
       ],
-      '@babel/proposal-class-properties',
-      '@babel/proposal-object-rest-spread',
-      '@babel/plugin-proposal-optional-chaining',
+      "@babel/proposal-class-properties",
+      "@babel/proposal-object-rest-spread",
+      "@babel/plugin-proposal-optional-chaining",
     ],
-  }
-  if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
-    common.plugins.push(['babel-plugin-styled-components', { displayName: true, minify: false }])
+  };
+  if (
+    process.env.NODE_ENV === "development" ||
+    process.env.NODE_ENV === "test"
+  ) {
+    common.plugins.push([
+      "babel-plugin-styled-components",
+      { displayName: true, minify: false },
+    ]);
   } else {
-    common.plugins.push(['babel-plugin-styled-components', { displayName: false, minify: true }])
+    common.plugins.push([
+      "babel-plugin-styled-components",
+      { displayName: false, minify: true },
+    ]);
   }
 
-  return common
-}
+  return common;
+};

+ 63 - 56
config.ts

@@ -1,11 +1,10 @@
-import type { Config } from '@src/@types/Config'
+import type { Config } from "@src/@types/Config";
 
 const conf: Config = {
-
   // The list of pages which will not appear in the navigation menu
   // Remove or comment to enable them
   disabledPages: [
-    'planning',
+    "planning",
     // Enabling users and projects page by default
     // 'users',
     // 'projects',
@@ -16,11 +15,11 @@ const conf: Config = {
   showUserDomainInput: false,
 
   // The default user domain name used for logging in
-  defaultUserDomain: 'default',
+  defaultUserDomain: "default",
 
   // The name of the admin role, used for checking
   // if a user is allowed to do certain admin operations
-  adminRoleName: 'admin',
+  adminRoleName: "admin",
 
   // Shows the 'Use Current User/Project/Domain for Authentification' switch
   // when creating a new openstack endpoint
@@ -37,12 +36,16 @@ const conf: Config = {
   // - If the `default` value is lower than the number of instances that
   // fit into a page, the latter number will be used.
   // - `Infinity` value means no `limit` will be used, i.e. all VMs will be listed.
-  instancesListBackgroundLoading: { default: 10, ovm: Infinity, 'hyper-v': Infinity },
+  instancesListBackgroundLoading: {
+    default: 10,
+    ovm: Infinity,
+    "hyper-v": Infinity,
+  },
 
   /**
    * The name of the Coriolis Bare Metal Hub enpoint used for doing Coriolis Bare Metal server operations.
    */
-  bareMetalEndpointName: 'appliance-metal-hub',
+  bareMetalEndpointName: "appliance-metal-hub",
 
   /**
    * The list of providers for which and extra source or destination options API call will be made.
@@ -54,42 +57,42 @@ const conf: Config = {
    */
   extraOptionsApiCalls: [
     {
-      name: 'openstack',
-      types: ['source'],
-      requiredFields: ['replica_export_mechanism'],
+      name: "openstack",
+      types: ["source"],
+      requiredFields: ["replica_export_mechanism"],
       requiredValues: [
         {
-          field: 'replica_export_mechanism',
-          values: ['swift_backups', 'ceph_backups', 'coriolis_backups'],
+          field: "replica_export_mechanism",
+          values: ["swift_backups", "ceph_backups", "coriolis_backups"],
         },
       ],
     },
     {
-      name: 'openstack',
-      types: ['destination'],
-      requiredFields: ['list_all_destination_networks'],
+      name: "openstack",
+      types: ["destination"],
+      requiredFields: ["list_all_destination_networks"],
     },
     {
-      name: 'aws',
-      types: ['source', 'destination'],
-      requiredFields: ['region'],
+      name: "aws",
+      types: ["source", "destination"],
+      requiredFields: ["region"],
     },
     {
-      name: 'azure',
-      types: ['source', 'destination'],
-      requiredFields: ['location', 'resource_group'],
+      name: "azure",
+      types: ["source", "destination"],
+      requiredFields: ["location", "resource_group"],
     },
     {
-      name: 'oci',
-      types: ['destination'],
-      requiredFields: ['compartment', 'availability_domain', 'vcn_compartment'],
-      relistFields: ['migr_image_map', 'migr_image'],
+      name: "oci",
+      types: ["destination"],
+      requiredFields: ["compartment", "availability_domain", "vcn_compartment"],
+      relistFields: ["migr_image_map", "migr_image"],
     },
     {
-      name: 'vmware_vsphere',
-      types: ['destination'],
-      requiredFields: ['import_datacenter'],
-      relistFields: ['import_cluster', 'migr_minion_cluster'],
+      name: "vmware_vsphere",
+      types: ["destination"],
+      requiredFields: ["import_datacenter"],
+      relistFields: ["import_cluster", "migr_minion_cluster"],
     },
   ],
 
@@ -104,7 +107,7 @@ const conf: Config = {
     openstack: 1,
     vmware_vsphere: 1,
     azure: 2,
-    'hyper-v': 2,
+    "hyper-v": 2,
     kubevirt: 2,
     scvmm: 2,
     oci: 3,
@@ -116,31 +119,35 @@ const conf: Config = {
   },
 
   providerNames: {
-    aws: 'AWS',
-    openstack: 'OpenStack',
-    vmware_vsphere: 'VMware',
-    azure: 'Azure',
-    'hyper-v': 'Hyper-V',
-    kubevirt: 'KubeVirt',
-    scvmm: 'SCVMM',
-    oci: 'OCI',
-    opc: 'Oracle Cloud',
-    oracle_vm: 'Oracle VM',
-    olvm: 'OLVM',
-    metal: 'Bare Metal',
-    rhev: 'Red Hat',
+    aws: "AWS",
+    openstack: "OpenStack",
+    vmware_vsphere: "VMware",
+    azure: "Azure",
+    "hyper-v": "Hyper-V",
+    kubevirt: "KubeVirt",
+    scvmm: "SCVMM",
+    oci: "OCI",
+    opc: "Oracle Cloud",
+    oracle_vm: "Oracle VM",
+    olvm: "OLVM",
+    metal: "Bare Metal",
+    rhev: "Red Hat",
   },
 
   // The list of providers for which to disable setting the 'Execute Now Options' field
-  providersDisabledExecuteOptions: ['metal'],
+  providersDisabledExecuteOptions: ["metal"],
 
   // The list of the users to hide in the UI
-  hiddenUsers: ['barbican', 'coriolis'],
+  hiddenUsers: ["barbican", "coriolis"],
 
   // By default, if a field name contains `password` in it (ex.: `user_password`),
   // it will be rendered as a password input
   // If the field doesn't contain `password` in its name, the following list will be used instead
-  passwordFields: ['private_key_passphrase', 'secret_access_key', 'client_secret'],
+  passwordFields: [
+    "private_key_passphrase",
+    "secret_access_key",
+    "client_secret",
+  ],
 
   // The number of items per page applicable to main lists:
   // replicas, migrations, endpoints, users etc.
@@ -149,15 +156,15 @@ const conf: Config = {
   maxMinionPoolEventsPerPage: 50,
 
   servicesUrls: {
-    keystone: '{BASE_URL}/identity',
-    barbican: '{BASE_URL}/barbican',
-    coriolis: '{BASE_URL}/coriolis',
-    coriolisLogs: '{BASE_URL}/logs',
-    coriolisLogStreamBaseUrl: '{BASE_URL}',
-    coriolisLicensing: '{BASE_URL}/licensing',
-    metalhub: '{BASE_URL}/metal-hub',
-    cloudbaseEmailEndpoint: 'http://localhost:3334',
+    keystone: "{BASE_URL}/identity",
+    barbican: "{BASE_URL}/barbican",
+    coriolis: "{BASE_URL}/coriolis",
+    coriolisLogs: "{BASE_URL}/logs",
+    coriolisLogStreamBaseUrl: "{BASE_URL}",
+    coriolisLicensing: "{BASE_URL}/licensing",
+    metalhub: "{BASE_URL}/metal-hub",
+    cloudbaseEmailEndpoint: "http://localhost:3334",
   },
-}
+};
 
-export const config = conf
+export const config = conf;

+ 10 - 13
jest.config.ts

@@ -31,7 +31,7 @@ export default {
   // ],
 
   // Indicates which provider should be used to instrument code for coverage
-  coverageProvider: 'v8',
+  coverageProvider: "v8",
 
   // A list of reporter names that Jest uses when writing coverage reports
   // coverageReporters: [
@@ -83,8 +83,8 @@ export default {
 
   // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
   moduleNameMapper: {
-    '@src/(.*)': '<rootDir>/src/$1',
-    '@tests/(.*)': '<rootDir>/tests/$1',
+    "@src/(.*)": "<rootDir>/src/$1",
+    "@tests/(.*)": "<rootDir>/tests/$1",
   },
 
   // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
@@ -129,9 +129,7 @@ export default {
   // runner: "jest-runner",
 
   // The paths to modules that run some code to configure or set up the testing environment before each test
-  setupFiles: [
-    '<rootDir>/tests/setup.js',
-  ],
+  setupFiles: ["<rootDir>/tests/setup.js"],
 
   // A list of paths to modules that run some code to configure or set up the testing framework before each test
   // setupFilesAfterEnv: [],
@@ -143,7 +141,7 @@ export default {
   // snapshotSerializers: [],
 
   // The test environment that will be used for testing
-  testEnvironment: 'jsdom',
+  testEnvironment: "jsdom",
 
   // Options that will be passed to the testEnvironment
   // testEnvironmentOptions: {},
@@ -152,9 +150,7 @@ export default {
   // testLocationInResults: false,
 
   // The glob patterns Jest uses to detect test files
-  testMatch: [
-    '**/*.spec.tsx',
-  ],
+  testMatch: ["**/*.spec.tsx"],
 
   // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
   // testPathIgnorePatterns: [
@@ -178,8 +174,9 @@ export default {
 
   // A map from regular expressions to paths to transformers
   transform: {
-    '\\.[jt]sx?$': 'babel-jest',
-    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/tests/fileTransform.js',
+    "\\.[jt]sx?$": "babel-jest",
+    "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
+      "<rootDir>/tests/fileTransform.js",
   },
 
   // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
@@ -199,4 +196,4 @@ export default {
 
   // Whether to use watchman for file crawling
   // watchman: true,
-}
+};

+ 28 - 27
webpack.common.js

@@ -1,38 +1,39 @@
-const HtmlWebpackPlugin = require('html-webpack-plugin')
-const webpack = require('webpack')
-const path = require('path')
-const { CleanWebpackPlugin } = require('clean-webpack-plugin')
-const CopyPlugin = require('copy-webpack-plugin')
-const dotenv = require('dotenv')
+/* eslint-disable @typescript-eslint/no-var-requires */
+const HtmlWebpackPlugin = require("html-webpack-plugin");
+const webpack = require("webpack");
+const path = require("path");
+const { CleanWebpackPlugin } = require("clean-webpack-plugin");
+const CopyPlugin = require("copy-webpack-plugin");
+const dotenv = require("dotenv");
 
-const dotenvConfig = dotenv && dotenv.config && dotenv.config()
-const env = (dotenvConfig && dotenvConfig.parsed) || process.env
+const dotenvConfig = dotenv && dotenv.config && dotenv.config();
+const env = (dotenvConfig && dotenvConfig.parsed) || process.env;
 const envKeys = Object.keys(env).reduce((prev, next) => {
   // eslint-disable-next-line no-param-reassign
-  prev[`process.env.${next}`] = JSON.stringify(env[next])
-  return prev
-}, {})
+  prev[`process.env.${next}`] = JSON.stringify(env[next]);
+  return prev;
+}, {});
 
 module.exports = {
-  entry: './src/index.tsx',
+  entry: "./src/index.tsx",
   output: {
-    filename: '[name].[hash].bundle.js',
-    chunkFilename: '[name].[hash].bundle.js',
-    path: path.resolve(__dirname, 'dist'),
-    publicPath: '/',
+    filename: "[name].[hash].bundle.js",
+    chunkFilename: "[name].[hash].bundle.js",
+    path: path.resolve(__dirname, "dist"),
+    publicPath: "/",
   },
   performance: { hints: false },
   plugins: [
     new webpack.DefinePlugin(envKeys),
     new CleanWebpackPlugin(),
-    new CopyPlugin({ patterns: ['./public'] }),
-    new HtmlWebpackPlugin({ template: './public/index.html' }),
+    new CopyPlugin({ patterns: ["./public"] }),
+    new HtmlWebpackPlugin({ template: "./public/index.html" }),
   ],
   resolve: {
-    modules: [__dirname, 'src', 'node_modules'],
-    extensions: ['*', '.js', '.jsx', '.tsx', '.ts'],
+    modules: [__dirname, "src", "node_modules"],
+    extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
     alias: {
-      '@src': path.resolve(__dirname, 'src/'),
+      "@src": path.resolve(__dirname, "src/"),
     },
   },
   module: {
@@ -40,14 +41,14 @@ module.exports = {
       {
         test: /\.tsx?$/,
         exclude: /node_modules/,
-        loader: require.resolve('babel-loader'),
+        loader: require.resolve("babel-loader"),
       },
       {
         test: /\.(png|jpe?g|svg|woff2?|ttf|eot)$/,
-        loader: 'url-loader',
+        loader: "url-loader",
         options: {
           limit: 8192,
-          name: './assets/[hash].[ext]',
+          name: "./assets/[hash].[ext]",
         },
       },
     ],
@@ -57,11 +58,11 @@ module.exports = {
       cacheGroups: {
         vendor: {
           test: /node_modules/,
-          chunks: 'initial',
-          name: 'vendor',
+          chunks: "initial",
+          name: "vendor",
           enforce: true,
         },
       },
     },
   },
-}
+};

+ 9 - 8
webpack.dev.js

@@ -1,17 +1,18 @@
-const merge = require('webpack-merge')
-const common = require('./webpack.common')
+/* eslint-disable @typescript-eslint/no-var-requires */
+const merge = require("webpack-merge");
+const common = require("./webpack.common");
 
 module.exports = merge(common, {
-  mode: 'development',
-  devtool: 'eval-source-map',
+  mode: "development",
+  devtool: "eval-source-map",
   devServer: {
     port: 3001,
     hot: true,
     historyApiFallback: true,
     proxy: {
-      '/api': `http://localhost:${process.env.PORT || 3000}`,
-      '/proxy': `http://localhost:${process.env.PORT || 3000}`,
+      "/api": `http://localhost:${process.env.PORT || 3000}`,
+      "/proxy": `http://localhost:${process.env.PORT || 3000}`,
     },
-    stats: 'minimal',
+    stats: "minimal",
   },
-})
+});

+ 6 - 5
webpack.prod.js

@@ -1,7 +1,8 @@
-const merge = require('webpack-merge')
-const common = require('./webpack.common')
+/* eslint-disable @typescript-eslint/no-var-requires */
+const merge = require("webpack-merge");
+const common = require("./webpack.common");
 
 module.exports = merge(common, {
-  mode: 'production',
-  devtool: 'source-map',
-})
+  mode: "production",
+  devtool: "source-map",
+});