Skip to content

Commit e5cee4c

Browse files
authored
AAP-19491: Enable pretifier for js and ts code on pre-commit (#782)
1 parent aba9dd1 commit e5cee4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3878
-3390
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ repos:
3434
hooks:
3535
- id: pyupgrade
3636
language_version: python3
37+
- repo: https://github.com/pre-commit/mirrors-prettier
38+
rev: v4.0.0-alpha.8
39+
hooks:
40+
- id: prettier
41+
types_or: [tsx, ts, javascript]
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// See https://youtrack.jetbrains.com/issue/WEB-54170/Allow-specifying-environment-variables-for-ESLint#focus=Comments-27-6031544.0-0
22
module.exports = {
3-
'extends': ['react-app', 'react-app/jest'],
4-
'parser': '@typescript-eslint/parser',
5-
'parserOptions': {
6-
'babelOptions': {
7-
'presets': [
8-
['babel-preset-react-app', false],
9-
(process.env.NODE_ENV === 'production')
10-
? 'babel-preset-react-app/prod'
11-
: (process.env.NODE_ENV === 'test')
12-
? 'babel-preset-react-app/test'
13-
: 'babel-preset-react-app/dev',
14-
],
15-
}
16-
}
17-
}
3+
extends: ["react-app", "react-app/jest"],
4+
parser: "@typescript-eslint/parser",
5+
parserOptions: {
6+
babelOptions: {
7+
presets: [
8+
["babel-preset-react-app", false],
9+
process.env.NODE_ENV === "production"
10+
? "babel-preset-react-app/prod"
11+
: process.env.NODE_ENV === "test"
12+
? "babel-preset-react-app/test"
13+
: "babel-preset-react-app/dev",
14+
],
15+
},
16+
},
17+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.css
2+
*.html
3+
*.svg
4+
*.json
5+
README.md
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
// Stub methods as needed (we should not need any for the Admin Portal)
2+
// Stub methods as needed (we should not need any for the Admin Portal)
33
};
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = {
2-
// Stub methods as needed...
3-
useTranslation: () => {
4-
return {
5-
t: (str: String) => str,
6-
};
7-
},
2+
// Stub methods as needed...
3+
useTranslation: () => {
4+
return {
5+
t: (str: String) => str,
6+
};
7+
},
88
};

ansible_wisdom_console_react/config/env.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
'use strict';
1+
"use strict";
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const paths = require('./paths');
3+
const fs = require("fs");
4+
const path = require("path");
5+
const paths = require("./paths");
66

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

1010
const NODE_ENV = process.env.NODE_ENV;
1111
if (!NODE_ENV) {
1212
throw new Error(
13-
'The NODE_ENV environment variable is required but was not specified.'
13+
"The NODE_ENV environment variable is required but was not specified.",
1414
);
1515
}
1616

@@ -20,7 +20,7 @@ const dotenvFiles = [
2020
// Don't include `.env.local` for `test` environment
2121
// since normally you expect tests to produce the same
2222
// results for everyone
23-
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
23+
NODE_ENV !== "test" && `${paths.dotenv}.local`,
2424
`${paths.dotenv}.${NODE_ENV}`,
2525
paths.dotenv,
2626
].filter(Boolean);
@@ -30,12 +30,12 @@ const dotenvFiles = [
3030
// that have already been set. Variable expansion is supported in .env files.
3131
// https://github.com/motdotla/dotenv
3232
// https://github.com/motdotla/dotenv-expand
33-
dotenvFiles.forEach(dotenvFile => {
33+
dotenvFiles.forEach((dotenvFile) => {
3434
if (fs.existsSync(dotenvFile)) {
35-
require('dotenv-expand')(
36-
require('dotenv').config({
35+
require("dotenv-expand")(
36+
require("dotenv").config({
3737
path: dotenvFile,
38-
})
38+
}),
3939
);
4040
}
4141
});
@@ -50,10 +50,10 @@ dotenvFiles.forEach(dotenvFile => {
5050
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
5151
// We also resolve them to make sure all tools using them work consistently.
5252
const appDirectory = fs.realpathSync(process.cwd());
53-
process.env.NODE_PATH = (process.env.NODE_PATH || '')
53+
process.env.NODE_PATH = (process.env.NODE_PATH || "")
5454
.split(path.delimiter)
55-
.filter(folder => folder && !path.isAbsolute(folder))
56-
.map(folder => path.resolve(appDirectory, folder))
55+
.filter((folder) => folder && !path.isAbsolute(folder))
56+
.map((folder) => path.resolve(appDirectory, folder))
5757
.join(path.delimiter);
5858

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

6363
function getClientEnvironment(publicUrl) {
6464
const raw = Object.keys(process.env)
65-
.filter(key => REACT_APP.test(key))
65+
.filter((key) => REACT_APP.test(key))
6666
.reduce(
6767
(env, key) => {
6868
env[key] = process.env[key];
@@ -71,7 +71,7 @@ function getClientEnvironment(publicUrl) {
7171
{
7272
// Useful for determining whether we’re running in production mode.
7373
// Most importantly, it switches React into the correct mode.
74-
NODE_ENV: process.env.NODE_ENV || 'development',
74+
NODE_ENV: process.env.NODE_ENV || "development",
7575
// Useful for resolving the correct path to static assets in `public`.
7676
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
7777
// This should only be used as an escape hatch. Normally you would put
@@ -87,12 +87,12 @@ function getClientEnvironment(publicUrl) {
8787
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
8888
// Whether or not react-refresh is enabled.
8989
// It is defined here so it is available in the webpackHotDevClient.
90-
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
91-
}
90+
FAST_REFRESH: process.env.FAST_REFRESH !== "false",
91+
},
9292
);
9393
// Stringify all values so we can feed into webpack DefinePlugin
9494
const stringified = {
95-
'process.env': Object.keys(raw).reduce((env, key) => {
95+
"process.env": Object.keys(raw).reduce((env, key) => {
9696
env[key] = JSON.stringify(raw[key]);
9797
return env;
9898
}, {}),

ansible_wisdom_console_react/config/getHttpsConfig.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
'use strict';
1+
"use strict";
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const crypto = require('crypto');
6-
const chalk = require('react-dev-utils/chalk');
7-
const paths = require('./paths');
3+
const fs = require("fs");
4+
const path = require("path");
5+
const crypto = require("crypto");
6+
const chalk = require("react-dev-utils/chalk");
7+
const paths = require("./paths");
88

99
// Ensure the certificate and key provided are valid and if not
1010
// throw an easy to debug error
1111
function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
1212
let encrypted;
1313
try {
1414
// publicEncrypt will throw an error with an invalid cert
15-
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
15+
encrypted = crypto.publicEncrypt(cert, Buffer.from("test"));
1616
} catch (err) {
1717
throw new Error(
18-
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
18+
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`,
1919
);
2020
}
2121

@@ -26,7 +26,7 @@ function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
2626
throw new Error(
2727
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
2828
err.message
29-
}`
29+
}`,
3030
);
3131
}
3232
}
@@ -36,8 +36,8 @@ function readEnvFile(file, type) {
3636
if (!fs.existsSync(file)) {
3737
throw new Error(
3838
`You specified ${chalk.cyan(
39-
type
40-
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
39+
type,
40+
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`,
4141
);
4242
}
4343
return fs.readFileSync(file);
@@ -47,14 +47,14 @@ function readEnvFile(file, type) {
4747
// Return cert files if provided in env, otherwise just true or false
4848
function getHttpsConfig() {
4949
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
50-
const isHttps = HTTPS === 'true';
50+
const isHttps = HTTPS === "true";
5151

5252
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
5353
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
5454
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
5555
const config = {
56-
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
57-
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
56+
cert: readEnvFile(crtFile, "SSL_CRT_FILE"),
57+
key: readEnvFile(keyFile, "SSL_KEY_FILE"),
5858
};
5959

6060
validateKeyAndCerts({ ...config, keyFile, crtFile });

ansible_wisdom_console_react/config/jest/babelTransform.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
'use strict';
1+
"use strict";
22

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

55
const hasJsxRuntime = (() => {
6-
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
6+
if (process.env.DISABLE_NEW_JSX_TRANSFORM === "true") {
77
return false;
88
}
99

1010
try {
11-
require.resolve('react/jsx-runtime');
11+
require.resolve("react/jsx-runtime");
1212
return true;
1313
} catch (e) {
1414
return false;
@@ -18,9 +18,9 @@ const hasJsxRuntime = (() => {
1818
module.exports = babelJest.createTransformer({
1919
presets: [
2020
[
21-
require.resolve('babel-preset-react-app'),
21+
require.resolve("babel-preset-react-app"),
2222
{
23-
runtime: hasJsxRuntime ? 'automatic' : 'classic',
23+
runtime: hasJsxRuntime ? "automatic" : "classic",
2424
},
2525
],
2626
],
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
'use strict';
1+
"use strict";
22

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

66
module.exports = {
7-
process() {
8-
return {
9-
code: `module.exports = {};`,
10-
};
11-
},
12-
getCacheKey() {
13-
// The output is always the same.
14-
return 'cssTransform';
15-
},
7+
process() {
8+
return {
9+
code: `module.exports = {};`,
10+
};
11+
},
12+
getCacheKey() {
13+
// The output is always the same.
14+
return "cssTransform";
15+
},
1616
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
'use strict';
1+
"use strict";
22

3-
const path = require('path');
3+
const path = require("path");
44

55
module.exports = {
66
process(sourceText, sourcePath, options) {
77
return {
88
code: `module.exports = ${JSON.stringify(path.basename(sourcePath))};`,
99
};
1010
},
11-
}
11+
};
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
global.matchMedia = global.matchMedia || function() {
1+
global.matchMedia =
2+
global.matchMedia ||
3+
function () {
24
return {
3-
matches : false,
4-
addListener : function() {},
5-
removeListener: function() {}
6-
}
7-
}
5+
matches: false,
6+
addListener: function () {},
7+
removeListener: function () {},
8+
};
9+
};

0 commit comments

Comments
 (0)