Skip to content

Commit 381d978

Browse files
alexeyr-ci2alexeyr
andauthored
Enable ESLint on dummy apps (#530)
Part 3 of #489, needs #529 to be merged. Closes #489. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Upgraded dependencies and streamlined build configurations for improved stability. - Added new steps for installing Node modules and Ruby gems in the CI workflow. - **Refactor** - Simplified component interfaces and standardized code styles. - Improved type safety and clarity in function parameters across various components. - Modified promise handling and control flow for better readability. - Updated object property merging syntax for better clarity. - **Style** - Enhanced accessibility with explicit image alt texts, button type definitions, and clearer label associations. - **Tests** - Refined test assertions for consistency and improved CI workflow for more reliable validations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alexey Romanov <[email protected]>
1 parent 156d5a2 commit 381d978

File tree

72 files changed

+1037
-1033
lines changed

Some content is hidden

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

72 files changed

+1037
-1033
lines changed

.circleci/config.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ aliases:
5252
bundle config set --local disable_checksum_validation true
5353
cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3
5454
55+
- &generate-dummy-app-packs
56+
name: Generate file-system based entrypoints
57+
command: |
58+
cd spec/dummy
59+
bundle exec rake react_on_rails:generate_packs
60+
5561
# Install ruby gems unless existing set of gems is satisfying bundler.
5662
- &install-package-ruby-gems
5763
name: Install Ruby Gems for package
@@ -119,6 +125,15 @@ jobs:
119125
- restore_cache: *restore-package-gem-cache
120126
- restore_cache: *restore-dummy-app-node-modules-cache
121127
- run: *install-package-ruby-gems
128+
- run: *install-package-node-modules
129+
- run: *install-dummy-app-ruby-gems
130+
- run: *install-dummy-app-node-modules
131+
- run:
132+
name: Install Node modules with Yarn for ExecJS dummy app
133+
command: |
134+
cd spec/execjs-compatible-dummy
135+
yarn install --frozen-lockfile --no-progress --no-emoji
136+
- run: *generate-dummy-app-packs
122137
- run: *lint-ruby
123138
- run: *lint-js
124139
- run: *format
@@ -200,9 +215,7 @@ jobs:
200215
- run: *install-package-node-modules
201216
- run: *install-dummy-app-node-modules
202217
- run: *install-dummy-app-ruby-gems
203-
- run:
204-
name: Generate file-system based entrypoints
205-
command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs
218+
- run: *generate-dummy-app-packs
206219
- run:
207220
name: Build test bundles for dummy app
208221
command: cd spec/dummy && yarn run build:test

eslint.config.mjs

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,22 @@ const compat = new FlatCompat({
1818
export default defineConfig([
1919
includeIgnoreFile(path.resolve(import.meta.dirname, '.gitignore')),
2020
globalIgnores([
21-
'**/node_modules',
22-
'**/coverage',
23-
'gen-documentation/**/*',
21+
'gen-documentation/',
2422
'spec/react_on_rails/dummy-for-generators',
25-
'spec/dummy',
26-
'spec/execjs-compatible-dummy',
23+
// includes some generated code
24+
'spec/dummy/client/app/packs/server-bundle.js',
2725
'packages/node-renderer/lib/',
2826
'packages/node-renderer/tests/fixtures',
29-
'packages/node-renderer/webpack.config.js',
30-
'**/node_modules/**/*',
31-
'**/assets/webpack/**/*',
32-
'**/generated/**/*',
27+
'**/node_modules/',
28+
'**/assets/webpack/',
29+
'**/generated/',
3330
'**/app/assets/javascripts/application.js',
34-
'**/coverage/**/*',
31+
'**/coverage/',
3532
'**/cable.js',
36-
'**/public/**/*',
37-
'**/tmp/**/*',
38-
'**/vendor',
39-
'**/dist',
33+
'**/public/',
34+
'**/tmp/',
35+
'**/vendor/',
36+
'**/dist/',
4037
'**/.yalc/',
4138
]),
4239
{
@@ -51,6 +48,10 @@ export default defineConfig([
5148
parserOptions: {
5249
// We have @babel/eslint-parser from eslint-config-shakacode, but don't use Babel in the main project
5350
requireConfigFile: false,
51+
52+
babelOptions: {
53+
presets: ['@babel/preset-env', '@babel/preset-react'],
54+
},
5455
},
5556
},
5657

@@ -62,14 +63,15 @@ export default defineConfig([
6263
},
6364

6465
'import/resolver': {
66+
alias: [['Assets', './spec/dummy/client/app/assets']],
6567
node: true,
6668
typescript: true,
6769
},
6870
},
6971

7072
rules: {
7173
'no-console': 'off',
72-
74+
'no-underscore-dangle': 'off',
7375
'no-void': [
7476
'error',
7577
{
@@ -94,6 +96,34 @@ export default defineConfig([
9496
},
9597
],
9698
'no-mixed-operators': 'off',
99+
'react/forbid-prop-types': 'off',
100+
'react/function-component-definition': [
101+
'error',
102+
{
103+
namedComponents: ['function-declaration', 'arrow-function'],
104+
unnamedComponents: 'arrow-function',
105+
},
106+
],
107+
'react/jsx-filename-extension': [
108+
'error',
109+
{
110+
extensions: ['.jsx', '.tsx'],
111+
},
112+
],
113+
'react/jsx-props-no-spreading': [
114+
'error',
115+
{
116+
custom: 'ignore',
117+
},
118+
],
119+
'react/prop-types': 'off',
120+
'react/static-property-placement': 'off',
121+
},
122+
},
123+
{
124+
files: ['spec/dummy/**/*', 'spec/execjs-compatible-dummy'],
125+
languageOptions: {
126+
globals: globals.browser,
97127
},
98128
},
99129
{
@@ -135,15 +165,9 @@ export default defineConfig([
135165
},
136166
},
137167
{
138-
files: ['packages/node-renderer/tests/**'],
139-
140-
plugins: {
141-
jest,
142-
},
168+
files: ['packages/node-renderer/tests/**', '**/*.test.{js,jsx,ts,tsx}'],
143169

144-
languageOptions: {
145-
globals: globals.jest,
146-
},
170+
extends: [jest.configs['flat/recommended'], jest.configs['flat/style']],
147171

148172
rules: {
149173
// Allows Jest mocks before import

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
"lockfile": "^1.0.4"
4848
},
4949
"devDependencies": {
50-
"@babel/core": "^7.12.3",
51-
"@babel/eslint-parser": "^7.24.1",
52-
"@babel/preset-env": "^7.12.1",
53-
"@babel/preset-typescript": "^7.24.1",
50+
"@babel/core": "^7.26.10",
51+
"@babel/eslint-parser": "^7.27.0",
52+
"@babel/preset-env": "^7.26.9",
53+
"@babel/preset-react": "^7.26.3",
54+
"@babel/preset-typescript": "^7.27.0",
5455
"@eslint/compat": "^1.2.8",
5556
"@honeybadger-io/js": "^6.10.1",
5657
"@sentry/node": "^7.120.0",
@@ -64,6 +65,7 @@
6465
"eslint": "^9.24.0",
6566
"eslint-config-prettier": "^10.1.1",
6667
"eslint-config-shakacode": "^19.0.0",
68+
"eslint-import-resolver-alias": "^1.1.2",
6769
"eslint-import-resolver-typescript": "^4.3.2",
6870
"eslint-plugin-import": "^2.31.0",
6971
"eslint-plugin-jest": "^28.11.0",

packages/node-renderer/tests/handleRenderRequest.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const renderResult = {
2828
data: JSON.stringify({ html: 'Dummy Object' }),
2929
};
3030

31+
// eslint-disable-next-line jest/valid-title
3132
describe(testName, () => {
3233
beforeEach(async () => {
3334
await resetForTest(testName);

packages/node-renderer/tests/vm.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ describe('buildVM and runInVM', () => {
542542
'typeof ReactOnRails !== "undefined" && ReactOnRails && typeof ReactOnRails.serverRenderReactComponent',
543543
serverBundlePath,
544544
);
545-
expect(ReactOnRails).toEqual('function');
545+
expect(ReactOnRails).toBe('function');
546546
});
547547

548548
test("running multiple buildVM in parallel doesn't cause runInVM to return partial results", async () => {
@@ -559,9 +559,9 @@ describe('buildVM and runInVM', () => {
559559
runCodeInVM(),
560560
runCodeInVM(),
561561
]);
562-
expect(runCodeInVM1).toEqual('function');
563-
expect(runCodeInVM2).toEqual('function');
564-
expect(runCodeInVM3).toEqual('function');
562+
expect(runCodeInVM1).toBe('function');
563+
expect(runCodeInVM2).toBe('function');
564+
expect(runCodeInVM3).toBe('function');
565565
});
566566
});
567567
});

packages/node-renderer/tests/worker.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ describe('worker', () => {
5757
.end();
5858
expect(res.statusCode).toBe(200);
5959
expect(res.headers['cache-control']).toBe('public, max-age=31536000');
60-
expect(res.payload).toEqual('{"html":"Dummy Object"}');
61-
expect(fs.existsSync(vmBundlePath(testName))).toEqual(true);
62-
expect(fs.existsSync(assetPath(testName))).toEqual(true);
63-
expect(fs.existsSync(assetPathOther(testName))).toEqual(true);
60+
expect(res.payload).toBe('{"html":"Dummy Object"}');
61+
expect(fs.existsSync(vmBundlePath(testName))).toBe(true);
62+
expect(fs.existsSync(assetPath(testName))).toBe(true);
63+
expect(fs.existsSync(assetPathOther(testName))).toBe(true);
6464
});
6565

6666
test(
@@ -138,7 +138,7 @@ describe('worker', () => {
138138
.end();
139139
expect(res.statusCode).toBe(200);
140140
expect(res.headers['cache-control']).toBe('public, max-age=31536000');
141-
expect(res.payload).toEqual('{"html":"Dummy Object"}');
141+
expect(res.payload).toBe('{"html":"Dummy Object"}');
142142
},
143143
);
144144

@@ -163,7 +163,7 @@ describe('worker', () => {
163163
});
164164
expect(res.headers['cache-control']).toBe('public, max-age=31536000');
165165
expect(res.statusCode).toBe(200);
166-
expect(res.payload).toEqual('{"html":"Dummy Object"}');
166+
expect(res.payload).toBe('{"html":"Dummy Object"}');
167167
},
168168
);
169169

@@ -222,7 +222,7 @@ describe('worker', () => {
222222
});
223223
const res = await app.inject().post(`/upload-assets`).payload(form.payload).headers(form.headers).end();
224224
expect(res.statusCode).toBe(200);
225-
expect(fs.existsSync(assetPath(testName))).toEqual(true);
226-
expect(fs.existsSync(assetPathOther(testName))).toEqual(true);
225+
expect(fs.existsSync(assetPath(testName))).toBe(true);
226+
expect(fs.existsSync(assetPathOther(testName))).toBe(true);
227227
});
228228
});

spec/dummy/babel.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
module.exports = function (api) {
2-
const defaultConfigFunc = require('shakapacker/package/babel/preset.js');
1+
const defaultConfigFunc = require('shakapacker/package/babel/preset.js');
2+
3+
module.exports = (api) => {
34
const resultConfig = defaultConfigFunc(api);
45
const isProductionEnv = api.env('production');
56
const side = api.caller((caller) => (caller && caller.ssr ? 'server' : 'client'));

spec/dummy/client/@types/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import type { SSRCache } from '@shakacode/use-ssr-computation.runtime/lib/ssrCac
44
declare global {
55
interface Window {
66
__APOLLO_STATE__: NormalizedCacheObject;
7-
__SSR_COMPUTATION_CACHE: SSRCache;
7+
__SSR_COMPUTATION_CACHE?: SSRCache;
88
}
99
}

spec/dummy/client/app/actions/HelloWorldActions.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as actionTypes from '../constants/HelloWorldConstants';
22

3-
/* eslint-disable import/prefer-default-export */
43
export function updateName(name) {
54
return {
65
type: actionTypes.HELLO_WORLD_NAME_UPDATE,

spec/dummy/client/app/components/ConsoleLogsInAsyncServer.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ const ConsoleLogsInAsyncServer = ({ requestId }) => (
77
Request ID: <b>{requestId}</b>
88
</p>
99
<p>
10-
Request ID should prefix all console logs logged on the server. You shouldn't see more than one request
11-
ID in the console logs.
10+
Request ID should prefix all console logs logged on the server. You shouldn&quot;t see more than one
11+
request ID in the console logs.
1212
</p>
1313

1414
<br />
1515

1616
<div>
1717
<p>
1818
If <code>replayServerAsyncOperationLogs</code> is set to <code>true</code> (or not set at all because
19-
it's the default value), you should see all logs either logged in sync or async server operations.
19+
it&quot;s the default value), you should see all logs either logged in sync or async server
20+
operations.
2021
</p>
2122

2223
<p>So, you should see the following logs in the console:</p>

0 commit comments

Comments
 (0)