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

Commit

Permalink
chore: consolidate eslint configs
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker committed Apr 2, 2024
1 parent 9b66220 commit d4ed3f5
Showing 62 changed files with 193 additions and 231 deletions.
150 changes: 150 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (c) 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
@@ -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: [
2 changes: 0 additions & 2 deletions __performance__/scripts/smoke.js
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 0 additions & 2 deletions __performance__/scripts/soak.js
Original file line number Diff line number Diff line change
@@ -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: [
2 changes: 0 additions & 2 deletions __performance__/scripts/spike.js
Original file line number Diff line number Diff line change
@@ -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: [
2 changes: 0 additions & 2 deletions __performance__/scripts/stress.js
Original file line number Diff line number Diff line change
@@ -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: [
2 changes: 0 additions & 2 deletions __tests__/client/initClient.spec.js
Original file line number Diff line number Diff line change
@@ -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();
@@ -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;
3 changes: 0 additions & 3 deletions __tests__/client/prerender.spec.js
Original file line number Diff line number Diff line change
@@ -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();

@@ -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 },
2 changes: 0 additions & 2 deletions __tests__/server/index.spec.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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
4 changes: 0 additions & 4 deletions __tests__/server/metrics/counters.spec.js
Original file line number Diff line number Diff line change
@@ -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;
@@ -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
@@ -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;
@@ -158,5 +156,3 @@ describe('gauges', () => {
});
});
});

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

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

describe('summaries', () => {
let Summary;
let register;
@@ -87,5 +85,3 @@ describe('summaries', () => {
});
});
});

/* eslint-enable no-underscore-dangle */
1 change: 0 additions & 1 deletion docs/guides/Making-An-Api-Call.md
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ const BooksModule = () => {
setData({ books, isLoading: false, fetchError: true });
}
} catch (e) {
// eslint-disable-next-line no-console -- debugging
console.error('Failed to fetch Books:', e);
setData({ books, isLoading: false, fetchError: true });
}
2 changes: 0 additions & 2 deletions docs/guides/Publishing-Modules.md
Original file line number Diff line number Diff line change
@@ -85,13 +85,11 @@ const updateModuleMap = async () => {
'./module_map/module-map.json', JSON.stringify(moduleMapContent, null, 2)
);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
};

updateModuleMap().catch((err) => {
// eslint-disable-next-line no-console
console.log(err);
});
```
Loading

0 comments on commit d4ed3f5

Please sign in to comment.