Skip to content

Commit

Permalink
Fix some uncaught eslint problems (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed May 17, 2022
1 parent 68c31cf commit 77becf5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
73 changes: 41 additions & 32 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,47 @@ module.exports = {
'jsdoc/require-returns-type': ['error', { contexts: ['TSFunctionType'] }],
'jsdoc/require-returns-description': ['error', { contexts: ['TSFunctionType'] }],
},
overrides: baseline.overrides.map((override) => {
return {
...override,
overrides: [
{
files: ['./packages/toolpad-app/**/*'],
extends: ['plugin:@next/next/recommended'],
rules: {
...override.rules,
'no-restricted-imports': ['off'],
'no-restricted-syntax': [
'error',
// From https://github.com/airbnb/javascript/blob/d8cb404da74c302506f91e5928f30cc75109e74d/packages/eslint-config-airbnb-base/rules/style.js#L333
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
// Too opinionated
// {
// selector: 'ForOfStatement',
// message:
// 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
// },
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
'@next/next/no-html-link-for-pages': ['error', 'packages/toolpad-app/pages/'],
},
};
}),
},
...baseline.overrides.map((override) => {
return {
...override,
rules: {
...override.rules,
'no-restricted-imports': ['off'],
'no-restricted-syntax': [
'error',
// From https://github.com/airbnb/javascript/blob/d8cb404da74c302506f91e5928f30cc75109e74d/packages/eslint-config-airbnb-base/rules/style.js#L333
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
// Too opinionated
// {
// selector: 'ForOfStatement',
// message:
// 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
// },
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
},
};
}),
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@mui/monorepo": "https://github.com/mui/material-ui.git#master",
"@next/eslint-plugin-next": "^12.1.6",
"@swc/core": "^1.2.163",
"@swc/helpers": "^0.3.8",
"@swc/jest": "^0.2.17",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default function EditorCanvasHost({

// eslint-disable-next-line no-underscore-dangle
if (frameWindow.__TOOLPAD_READY__ === true) {
// eslint-disable-next-line no-underscore-dangle
onReadyRef.current?.(frameWindow);
// eslint-disable-next-line no-underscore-dangle
} else if (typeof frameWindow.__TOOLPAD_READY__ !== 'function') {
Expand Down
10 changes: 5 additions & 5 deletions packages/toolpad-app/src/runtime/createRequire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ export default async function createRequire(urlImports: string[]) {
);

const require = (moduleId: string): unknown => {
let module = modules.get(moduleId);
let esModule = modules.get(moduleId);

if (!module) {
if (!esModule) {
// Custom solution for icons
const iconMatch = /^@mui\/icons-material\/(.*)$/.exec(moduleId);
if (iconMatch) {
const iconName = iconMatch[1];
const iconsModule = modules.get('@mui/icons-material');
module = { default: (iconsModule as any)[iconName] };
esModule = { default: (iconsModule as any)[iconName] };
}
}

if (module && typeof module === 'object') {
if (esModule && typeof esModule === 'object') {
// ESM interop
return { ...module, __esModule: true };
return { ...esModule, __esModule: true };
}

throw new Error(`Can't resolve module "${moduleId}"`);
Expand Down
2 changes: 0 additions & 2 deletions packages/toolpad-app/src/runtime/evalJsBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export interface ParsedBinding<T = unknown> {

export function buildGlobalScope(bindings: Record<string, ParsedBinding>): Record<string, unknown> {
const globalScope = {};
// eslint-disable-next-line no-restricted-syntax
for (const binding of Object.values(bindings)) {
if (binding.scopePath) {
const value = binding.result?.value;
Expand All @@ -101,7 +100,6 @@ export default function evalJsBindings(
const bindingsMap = new Map(Object.entries(bindings));

const bindingIdMap = new Map<string, string>();
// eslint-disable-next-line no-restricted-syntax
for (const [bindingId, binding] of bindingsMap) {
if (binding.scopePath) {
bindingIdMap.set(binding.scopePath, bindingId);
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,13 @@
dependencies:
glob "7.1.7"

"@next/eslint-plugin-next@^12.1.6":
version "12.1.6"
resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-12.1.6.tgz#dde3f98831f15923b25244588d924c716956292e"
integrity sha512-yNUtJ90NEiYFT6TJnNyofKMPYqirKDwpahcbxBgSIuABwYOdkGwzos1ZkYD51Qf0diYwpQZBeVqElTk7Q2WNqw==
dependencies:
glob "7.1.7"

"@next/swc-android-arm-eabi@12.1.4":
version "12.1.4"
resolved "https://registry.yarnpkg.com/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-12.1.4.tgz#c3dae178b7c15ad627d2e9b8dfb38caecb5c4ac7"
Expand Down

0 comments on commit 77becf5

Please sign in to comment.