Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

chore: consolidate eslint configs #1364

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

const allowedDangles = [
// one-app
'__INITIAL_STATE__',
'__render_mode__',
// holocron
'__CLIENT_HOLOCRON_MODULE_MAP__',
'__HOLOCRON_EXTERNALS__',
// redux
'__REDUX_DEVTOOLS_EXTENSION_COMPOSE__',
// prom-client
'_metrics',
// lean-intl
'__addLocaleData',
// webpack
'__webpack_public_path__',
];

module.exports = {
root: true,
extends: 'amex',
plugins: ['es'],
parserOptions: {
babelOptions: {
presets: ['@babel/preset-react'],
},
},
rules: {
'unicorn/prefer-node-protocol': 'error',
'eslint-comments/require-description': ['error', { ignore: ['eslint-enable'] }],
'no-underscore-dangle': ['error', { allow: allowedDangles }],
'default-param-last': 0,
},
overrides: [
{
files: ['__performance__/**'],
globals: {
__ENV: true,
},
rules: {
// These scripts are not run directly, and the k6 package is a placeholder
'import/no-unresolved': ['error', { ignore: ['k6'] }],
},
},
{
files: [
'**/__mocks__/**',
'**/__tests__/**',
],
extends: 'amex/test',
rules: {
// a lot of tests require changing the environment the file is started in
'global-require': 0,
// this is a server, a lot of console spies are added
'no-console': 0,
'no-underscore-dangle': ['error', { allow: allowedDangles }],
},
},
{
files: ['src/server/**'],
rules: {
// console methods are how we log events
'no-console': 0,
},
},
{
files: [
// Parts of the server that are only used in development
'src/server/devHolocronCDN.js',
'src/server/utils/devCdnFactory.js',
'src/server/utils/watchLocalModules.js',
'src/server/utils/logging/config/development.js',
// Client service worker just needs `@americanexpress/one-service-worker` at build time
'src/client/service-worker/**',
],
rules: {
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
},
{
files: ['src/client/service-worker/**'],
rules: {
// for clearer error reporting, having anonymous functions may inhibit us from
// collecting a concise stack trace with the proper names of invoked functions
'prefer-arrow-callback': 'off',
// generally, self is acceptable to use in a service worker script
// we want to allow this behavior throughout
'no-restricted-globals': ['off', 'self'],
},
},
{
// Allow console logs in documentation
files: ['**/*.md/*.{js,javascript,jsx,node}'],
rules: {
'no-console': 0,
},
},
{
files: ['prod-sample/**'],
rules: {
'import/no-unresolved': 'off',
},
},
{
files: ['prod-sample/sample-modules/**'],
rules: {
'react/no-unknown-property': ['error', { ignore: ['css'] }],
},
},
{
files: [
'scripts/**',
'one-app-statics/**',
],
rules: {
// these scripts should be used only during development
'import/no-extraneous-dependencies': ['error', { devDependencies: true, optionalDependencies: true, peerDependencies: false }],
// we need to message the user for DX
'no-console': 'off',
'global-require': 'off',
'import/no-dynamic-require': 'off',
},
},
{
files: ['scripts/dangers/**'],
globals: {
danger: 'readonly',
fail: 'readonly',
markdown: 'readonly',
message: 'readonly',
peril: 'readonly',
schedule: 'readonly',
warn: 'readonly',
},
},
],
};
71 changes: 0 additions & 71 deletions .eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions __performance__/scripts/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* permissions and limitations under the License.
*/

/* eslint-disable import/no-unresolved -- performance scripts are not ran directly */
import http from 'k6/http';
import { check, sleep } from 'k6';
/* eslint-enable import/no-unresolved */

export const options = {
stages: [
Expand Down
2 changes: 0 additions & 2 deletions __performance__/scripts/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* permissions and limitations under the License.
*/

/* eslint-disable import/no-unresolved -- performance scripts are not ran directly */
import http from 'k6/http';
import { check, sleep } from 'k6';
/* eslint-enable import/no-unresolved */

// This is a simple smoke test to ensure there is no major regression
// to the one-app server.
Expand Down
2 changes: 0 additions & 2 deletions __performance__/scripts/soak.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* permissions and limitations under the License.
*/

/* eslint-disable import/no-unresolved -- performance scripts are not ran directly */
import http from 'k6/http';
import { check, sleep } from 'k6';
/* eslint-enable import/no-unresolved */

export const options = {
stages: [
Expand Down
2 changes: 0 additions & 2 deletions __performance__/scripts/spike.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* permissions and limitations under the License.
*/

/* eslint-disable import/no-unresolved -- performance scripts are not ran directly */
import http from 'k6/http';
import { check, sleep } from 'k6';
/* eslint-enable import/no-unresolved */

export const options = {
stages: [
Expand Down
2 changes: 0 additions & 2 deletions __performance__/scripts/stress.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* permissions and limitations under the License.
*/

/* eslint-disable import/no-unresolved -- performance scripts are not ran directly */
import http from 'k6/http';
import { check, sleep } from 'k6';
/* eslint-enable import/no-unresolved */

export const options = {
stages: [
Expand Down
2 changes: 0 additions & 2 deletions __tests__/client/initClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ describe('initClient', () => {

beforeEach(() => {
global.fetch = jest.fn(() => Promise.resolve());
// eslint-disable-next-line no-underscore-dangle -- private API
global.__CLIENT_HOLOCRON_MODULE_MAP__ = clientHolocronModuleMap;
jest.resetModules();
jest.clearAllMocks();
Expand Down Expand Up @@ -145,7 +144,6 @@ describe('initClient', () => {
loadPrerenderScripts.mockReturnValueOnce(Promise.resolve());
promiseResolveSpy.mockRestore();

// eslint-disable-next-line no-underscore-dangle -- private API
global.__render_mode__ = 'render';

const initClient = require('../../src/client/initClient').default;
Expand Down
3 changes: 0 additions & 3 deletions __tests__/client/prerender.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ describe('initializeClientStore', () => {
});

afterEach(() => {
// eslint-disable-next-line no-underscore-dangle -- private API
global.__INITIAL_STATE__ = undefined;
});

it('should create the store with initial state if it exists', async () => {
// eslint-disable-next-line no-underscore-dangle -- private API
global.__INITIAL_STATE__ = fromJS({ some: 'state' });
initializeClientStore();

Expand All @@ -78,7 +76,6 @@ describe('initializeClientStore', () => {
} = createHolocronStore.mock.calls[0][0];

await expect(fetchClient()).resolves.toEqual({ data: 'data', timeout: 6000 });
// eslint-disable-next-line no-underscore-dangle -- private API
expect(transitFromJson).toHaveBeenCalledWith(global.__INITIAL_STATE__);
expect(createHolocronStore).toHaveBeenCalledWith({
enhancer: 'enhancer', initialState: 'initial state', reducer: 'reducers', extraThunkArguments: { fetchClient },
Expand Down
6 changes: 3 additions & 3 deletions __tests__/integration/one-app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ describe('Tests that require Docker setup', () => {
'one-app-version': [expect.any(String)],
'referrer-policy': ['same-origin'],
'strict-transport-security': ['max-age=63072000; includeSubDomains'],
vary: ['Accept-Encoding, accept-encoding'],
vary: ['Accept-Encoding'],
'x-content-type-options': ['nosniff'],
'x-dns-prefetch-control': ['off'],
'x-download-options': ['noopen'],
Expand Down Expand Up @@ -1632,7 +1632,7 @@ describe('Tests that require Docker setup', () => {
'referrer-policy': ['no-referrer'],
'strict-transport-security': ['max-age=63072000; includeSubDomains'],
traceid: [expect.any(String)],
vary: ['Accept-Encoding, accept-encoding'],
vary: ['Accept-Encoding'],
'x-content-type-options': ['nosniff'],
'x-dns-prefetch-control': ['off'],
'x-download-options': ['noopen'],
Expand Down Expand Up @@ -1925,7 +1925,7 @@ describe('Tests that can run against either local Docker setup or remote One App
);
const body = await response.text();
expect(body).toBe(
'<style class="ssr-css">.frank-lloyd-root__styles__stylish___2aiGw{color:orchid}</style><pre class="value-provided-from-config">https://intranet-origin-dev.example.com/some-api/v1</pre><span class="message">Hello!</span>'
'<style id="90ac7139df6563d22a4a856f04cacf522587d2ec6e66ddb89d06ff844b5bee7c" data-ssr="true">._stylish_1wkbg_1{color:orchid}</style><pre class="value-provided-from-config">https://intranet-origin-dev.example.com/some-api/v1</pre><span class="message">Hello!</span>'
Copy link
Member Author

Choose a reason for hiding this comment

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

This is related to updating the bundler in sample modules

);
});
});
Expand Down
2 changes: 0 additions & 2 deletions __tests__/server/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ describe('server index', () => {

it('initializes Intl with a locale', async () => {
await load();
// eslint-disable-next-line no-underscore-dangle -- lean-intl API
expect(require('lean-intl').__addLocaleData.mock.calls[0][0]).toMatchObject({
// contents dont have to exactly match just need to make sure that a locale object
// is being added and not some random other thing
Expand Down Expand Up @@ -291,7 +290,6 @@ describe('server index', () => {

it('initializes Intl with a locale', async () => {
await load();
// eslint-disable-next-line no-underscore-dangle -- lean-intl API
expect(require('lean-intl').__addLocaleData.mock.calls[0][0]).toMatchObject({
// contents dont have to exactly match just need to make sure that a locale object
// is being added and not some random other thing
Expand Down
4 changes: 0 additions & 4 deletions __tests__/server/metrics/counters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* permissions and limitations under the License.
*/

/* eslint-disable no-underscore-dangle -- prom-client uses dangling underscore */

describe('counters', () => {
let Counter;
let register;
Expand Down Expand Up @@ -93,5 +91,3 @@ describe('counters', () => {
});
});
});

/* eslint-enable no-underscore-dangle */
4 changes: 0 additions & 4 deletions __tests__/server/metrics/gauges.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* permissions and limitations under the License.
*/

/* eslint-disable no-underscore-dangle -- prom-client uses dangling underscore */

describe('gauges', () => {
let Gauge;
let register;
Expand Down Expand Up @@ -158,5 +156,3 @@ describe('gauges', () => {
});
});
});

/* eslint-enable no-underscore-dangle */
Loading
Loading