Skip to content

Commit

Permalink
AAP-19491: Enable pretifier for js and ts code on pre-commit (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasys authored Jan 12, 2024
1 parent aba9dd1 commit e5cee4c
Show file tree
Hide file tree
Showing 63 changed files with 3,878 additions and 3,390 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ repos:
hooks:
- id: pyupgrade
language_version: python3
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
types_or: [tsx, ts, javascript]
30 changes: 15 additions & 15 deletions ansible_wisdom_console_react/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// See https://youtrack.jetbrains.com/issue/WEB-54170/Allow-specifying-environment-variables-for-ESLint#focus=Comments-27-6031544.0-0
module.exports = {
'extends': ['react-app', 'react-app/jest'],
'parser': '@typescript-eslint/parser',
'parserOptions': {
'babelOptions': {
'presets': [
['babel-preset-react-app', false],
(process.env.NODE_ENV === 'production')
? 'babel-preset-react-app/prod'
: (process.env.NODE_ENV === 'test')
? 'babel-preset-react-app/test'
: 'babel-preset-react-app/dev',
],
}
}
}
extends: ["react-app", "react-app/jest"],
parser: "@typescript-eslint/parser",
parserOptions: {
babelOptions: {
presets: [
["babel-preset-react-app", false],
process.env.NODE_ENV === "production"
? "babel-preset-react-app/prod"
: process.env.NODE_ENV === "test"
? "babel-preset-react-app/test"
: "babel-preset-react-app/dev",
],
},
},
};
5 changes: 5 additions & 0 deletions ansible_wisdom_console_react/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.css
*.html
*.svg
*.json
README.md
2 changes: 1 addition & 1 deletion ansible_wisdom_console_react/__mocks__/monaco-editor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
// Stub methods as needed (we should not need any for the Admin Portal)
// Stub methods as needed (we should not need any for the Admin Portal)
};
12 changes: 6 additions & 6 deletions ansible_wisdom_console_react/__mocks__/react-i18next.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
// Stub methods as needed...
useTranslation: () => {
return {
t: (str: String) => str,
};
},
// Stub methods as needed...
useTranslation: () => {
return {
t: (str: String) => str,
};
},
};
38 changes: 19 additions & 19 deletions ansible_wisdom_console_react/config/env.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';
"use strict";

const fs = require('fs');
const path = require('path');
const paths = require('./paths');
const fs = require("fs");
const path = require("path");
const paths = require("./paths");

// Make sure that including paths.js after env.js will read .env variables.
delete require.cache[require.resolve('./paths')];
delete require.cache[require.resolve("./paths")];

const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
throw new Error(
'The NODE_ENV environment variable is required but was not specified.'
"The NODE_ENV environment variable is required but was not specified.",
);
}

Expand All @@ -20,7 +20,7 @@ const dotenvFiles = [
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
NODE_ENV !== "test" && `${paths.dotenv}.local`,
`${paths.dotenv}.${NODE_ENV}`,
paths.dotenv,
].filter(Boolean);
Expand All @@ -30,12 +30,12 @@ const dotenvFiles = [
// that have already been set. Variable expansion is supported in .env files.
// https://github.com/motdotla/dotenv
// https://github.com/motdotla/dotenv-expand
dotenvFiles.forEach(dotenvFile => {
dotenvFiles.forEach((dotenvFile) => {
if (fs.existsSync(dotenvFile)) {
require('dotenv-expand')(
require('dotenv').config({
require("dotenv-expand")(
require("dotenv").config({
path: dotenvFile,
})
}),
);
}
});
Expand All @@ -50,10 +50,10 @@ dotenvFiles.forEach(dotenvFile => {
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
// We also resolve them to make sure all tools using them work consistently.
const appDirectory = fs.realpathSync(process.cwd());
process.env.NODE_PATH = (process.env.NODE_PATH || '')
process.env.NODE_PATH = (process.env.NODE_PATH || "")
.split(path.delimiter)
.filter(folder => folder && !path.isAbsolute(folder))
.map(folder => path.resolve(appDirectory, folder))
.filter((folder) => folder && !path.isAbsolute(folder))
.map((folder) => path.resolve(appDirectory, folder))
.join(path.delimiter);

// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
Expand All @@ -62,7 +62,7 @@ const REACT_APP = /^REACT_APP_/i;

function getClientEnvironment(publicUrl) {
const raw = Object.keys(process.env)
.filter(key => REACT_APP.test(key))
.filter((key) => REACT_APP.test(key))
.reduce(
(env, key) => {
env[key] = process.env[key];
Expand All @@ -71,7 +71,7 @@ function getClientEnvironment(publicUrl) {
{
// Useful for determining whether we’re running in production mode.
// Most importantly, it switches React into the correct mode.
NODE_ENV: process.env.NODE_ENV || 'development',
NODE_ENV: process.env.NODE_ENV || "development",
// Useful for resolving the correct path to static assets in `public`.
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
// This should only be used as an escape hatch. Normally you would put
Expand All @@ -87,12 +87,12 @@ function getClientEnvironment(publicUrl) {
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
// Whether or not react-refresh is enabled.
// It is defined here so it is available in the webpackHotDevClient.
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
}
FAST_REFRESH: process.env.FAST_REFRESH !== "false",
},
);
// Stringify all values so we can feed into webpack DefinePlugin
const stringified = {
'process.env': Object.keys(raw).reduce((env, key) => {
"process.env": Object.keys(raw).reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
return env;
}, {}),
Expand Down
28 changes: 14 additions & 14 deletions ansible_wisdom_console_react/config/getHttpsConfig.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict';
"use strict";

const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const chalk = require('react-dev-utils/chalk');
const paths = require('./paths');
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const chalk = require("react-dev-utils/chalk");
const paths = require("./paths");

// Ensure the certificate and key provided are valid and if not
// throw an easy to debug error
function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
let encrypted;
try {
// publicEncrypt will throw an error with an invalid cert
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
encrypted = crypto.publicEncrypt(cert, Buffer.from("test"));
} catch (err) {
throw new Error(
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`,
);
}

Expand All @@ -26,7 +26,7 @@ function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
throw new Error(
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
err.message
}`
}`,
);
}
}
Expand All @@ -36,8 +36,8 @@ function readEnvFile(file, type) {
if (!fs.existsSync(file)) {
throw new Error(
`You specified ${chalk.cyan(
type
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
type,
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`,
);
}
return fs.readFileSync(file);
Expand All @@ -47,14 +47,14 @@ function readEnvFile(file, type) {
// Return cert files if provided in env, otherwise just true or false
function getHttpsConfig() {
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
const isHttps = HTTPS === 'true';
const isHttps = HTTPS === "true";

if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
const config = {
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
cert: readEnvFile(crtFile, "SSL_CRT_FILE"),
key: readEnvFile(keyFile, "SSL_KEY_FILE"),
};

validateKeyAndCerts({ ...config, keyFile, crtFile });
Expand Down
12 changes: 6 additions & 6 deletions ansible_wisdom_console_react/config/jest/babelTransform.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';
"use strict";

const babelJest = require('babel-jest').default;
const babelJest = require("babel-jest").default;

const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === "true") {
return false;
}

try {
require.resolve('react/jsx-runtime');
require.resolve("react/jsx-runtime");
return true;
} catch (e) {
return false;
Expand All @@ -18,9 +18,9 @@ const hasJsxRuntime = (() => {
module.exports = babelJest.createTransformer({
presets: [
[
require.resolve('babel-preset-react-app'),
require.resolve("babel-preset-react-app"),
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
runtime: hasJsxRuntime ? "automatic" : "classic",
},
],
],
Expand Down
20 changes: 10 additions & 10 deletions ansible_wisdom_console_react/config/jest/cssTransform.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';
"use strict";

// This is a custom Jest transformer turning style imports into empty objects.
// http://facebook.github.io/jest/docs/en/webpack.html

module.exports = {
process() {
return {
code: `module.exports = {};`,
};
},
getCacheKey() {
// The output is always the same.
return 'cssTransform';
},
process() {
return {
code: `module.exports = {};`,
};
},
getCacheKey() {
// The output is always the same.
return "cssTransform";
},
};
6 changes: 3 additions & 3 deletions ansible_wisdom_console_react/config/jest/fileTransform.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
"use strict";

const path = require('path');
const path = require("path");

module.exports = {
process(sourceText, sourcePath, options) {
return {
code: `module.exports = ${JSON.stringify(path.basename(sourcePath))};`,
};
},
}
};
14 changes: 8 additions & 6 deletions ansible_wisdom_console_react/config/jest/matchMedia.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
global.matchMedia = global.matchMedia || function() {
global.matchMedia =
global.matchMedia ||
function () {
return {
matches : false,
addListener : function() {},
removeListener: function() {}
}
}
matches: false,
addListener: function () {},
removeListener: function () {},
};
};
Loading

1 comment on commit e5cee4c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClamAV Virus Definition DB Files:
----
total 227916
-rw-r--r--  1 root root 170479789 Jan 12 06:07 main.cvd
-rw-r--r--  1 root root        69 Jan 12 06:07 freshclam.dat
-rw-r--r--  1 root root  62583308 Jan 12 06:07 daily.cvd
-rw-r--r--  1 root root    291965 Jan 12 06:08 bytecode.cvd
drwxr-xr-x 16 root root      4096 Jan 12 16:23 ..
drwxr-xr-x  2 root root      4096 Jan 12 16:23 .
----
File: /var/lib/clamav/bytecode.cvd
Build time: 22 Feb 2023 16:33 -0500
Version: 334
Signatures: 91
Functionality level: 90
Builder: anvilleg
MD5: 0464067a252b1e937012ad34e811065f
Digital signature: urVBCbhJcz8v6i1E6HedDwa8TxBHnJknqg7SE+6JWBtovATpw8MWwS+kvGAi//x5u0LIFwhPvUsgEBBeFiZE0QTTWazOhJ/LfKJK+nODqha6cTvaQdKl2rSbEOv6grv7UONV8eKi383Wv07wfSNYp+lPNpt0QmejKb1TMHAYTA
Verification OK.
----
File: /var/lib/clamav/daily.cvd
Build time: 11 Jan 2024 04:41 -0500
Version: 27151
Signatures: 2050633
Functionality level: 90
Builder: raynman
MD5: f710ab04c1ab1b5242ffb6a8d4675680
Digital signature: Ahr8y1EozSNa/roLLQTsZ6OsK5u4szI7YdWroIMEq3Y3MDF8PSSY7XwnREpygwCxeYj4PciCePMvk6YKTfnshzsyPTMX3EPfD/c/YKTksW2f9ZJU4T5X3U/JDg3VM/sc15DbYJOaQ/ZdNT1CUGTDarvNy9i5lxUyPQz3tmxwwvd
Verification OK.
----
File: /var/lib/clamav/main.cvd
Build time: 16 Sep 2021 08:32 -0400
Version: 62
Signatures: 6647427
Functionality level: 90
Builder: sigmgr
MD5: 137eccce31aacb21b5a98bb8c21cefd6
Digital signature: twaJBls8V5q64R7QY10AatEtPNuPWoVoxTaNO1jpBg7s5jIMMXpitgG1000YLp6rb0TWkEKjRqxneGTxuxWaWm7XBjsgwX2BRWh/y4fhs7uyImdKRLzQ5y8e2EkSChegF/i8clqfn+1qetq9j4gbktJ3JZpOXPoHlyr2Dv9S/Bg
Verification OK.
----
Scanning Results:
ClamAV 1.0.4/27151/Thu Jan 11 09:41:16 2024
LibClamAV Warning: Max file-size was set to 4194304000 bytes. Unfortunately, scanning files greater than 2147483647 bytes (2 GiB - 1) is not supported.

----------- SCAN SUMMARY -----------
Known viruses: 8682506
Engine version: 1.0.4
Scanned directories: 30949
Scanned files: 190131
Infected files: 0
Data scanned: 6493.40 MB
Data read: 3410.38 MB (ratio 1.90:1)
Time: 2052.735 sec (34 m 12 s)
Start Date: 2024:01:12 16:25:24
End Date:   2024:01:12 16:59:36

Please sign in to comment.