小编Dyl*_* Ju的帖子

eslint 不处理多个 package.json

我的项目有两个package.json

\n\n
root folder\n\n\xe2\x94\x94 app ---- /public\n         \xe2\x94\x94 /styles\n         \xe2\x94\x94 /src\n         \xe2\x94\x94 package.json\n         \xe2\x94\x94 eslintrc.json\n         \xe2\x94\x94 webpack.config.js\n\n\xe2\x94\x94 server - /something\n         \xe2\x94\x94 /something\n\n\xe2\x94\x94 package.json\n\xe2\x94\x94 ...etc\n
Run Code Online (Sandbox Code Playgroud)\n\n

Atom 编辑器显示 lint 错误

\n\n
import React from \'react\';\n// \'react\' should be listed in the project\'s dependencies. Run \'npm i -S react\' to add it (import/no-extraneous-dependencies)\n
Run Code Online (Sandbox Code Playgroud)\n\n

在 package.json 中

\n\n
"dependencies": {\n  "@types/chart.js": "^2.6.8",\n  "@types/react": "^16.0.10",\n  "@types/react-dom": "^16.0.1",\n  "bootstrap": "^4.0.0-beta",\n  "chart.js": "2.6.0",\n  "font-awesome": "^4.7.0",\n  "history": "4.7.2",\n  "jwt-decode": "^2.2.0",\n  "prop-types": "^15.6.0",\n  "react": "^15.6.1",\n  "react-chartjs-2": "2.6.1",\n …
Run Code Online (Sandbox Code Playgroud)

javascript lint npm eslint atom-editor

6
推荐指数
2
解决办法
3193
查看次数

如何为“layerX”和“layerY”设置事件类型

我正在制作一个具有绝对位置的下拉菜单。它从鼠标事件获取 x、y 坐标。

container.addEventListener(
  'contextmenu',
    (e: MouseEvent) => {
      drawingMenuX = e.layerX + 15; // chartiq basic padding is 15
      drawingMenuY = e.layerY + 15;
    },
    false,
);
Run Code Online (Sandbox Code Playgroud)

但它显示错误“属性‘layerX’在类型‘MouseEvent’.ts(2339)上不存在”。如何设置正确的事件类型而不是 MouseEvent?

types addeventlistener typescript

5
推荐指数
1
解决办法
3257
查看次数

@testing-library/react (rtl) 'waitFor' 在没有await关键字的情况下只会成功

await waitFor()使我的测试失败,但waitFor()使我的测试成功(无需等待)。

官方医生说

异步方法返回一个 Promise,因此在调用它们时必须始终使用await 或.then(done)。(https://testing-library.com/docs/guide-disappearance

我不知道如何才能正确测试。我必须使用吗rerender

it('toggles active status', async () => {
  render(<List {...listProps} />);
  const targetItem = screen.getByRole('heading', { name: /first/i });

  // de-active color is GRAY2, active color is MINT
  expect(targetItem).toHaveStyle({ color: GRAY2 });

  // click to change the color of targetItem
  // it dispatch action that update listProps
  // So changing listProps makes <List /> re-rendering
  fireEvent.click(targetItem);

  await waitFor(() => {
    // It throws an error because the …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs react-testing-library

5
推荐指数
1
解决办法
4823
查看次数

eslint object-curly-newline 冲突更漂亮的多行基本原理

我是漂亮 + 打字稿 + eslint 的新手。大多数集成工作正常,但解构对象中的多行则不然。

Prettier 1.19.1 游乐场链接

输入:

const {
  ciq,
  drawingMenuX,
  drawingMenuY,
  selectedDrawing,
} = store.chartStore;
Run Code Online (Sandbox Code Playgroud)

输出:

const { ciq, drawingMenuX, drawingMenuY, selectedDrawing } = store.chartStore;
Run Code Online (Sandbox Code Playgroud)

预期行为:

const {
  ciq,
  drawingMenuX,
  drawingMenuY,
  selectedDrawing,
} = store.chartStore;
Run Code Online (Sandbox Code Playgroud)

我想在像基本原理一样的解构对象中保留多行格式(https://prettier.io/docs/en/rationale.html#multi-line-objects

它适用于普通对象,但不适用于解构对象

我该如何解决这个问题?我只需要修复每一行吗?

包.json

"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"eslint": "^6.7.2",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^1.7.0",
"prettier": "^1.19.1",
Run Code Online (Sandbox Code Playgroud)

.eslintrc.js

const {
  ciq,
  drawingMenuX,
  drawingMenuY,
  selectedDrawing,
} = store.chartStore;
Run Code Online (Sandbox Code Playgroud)

javascript typescript eslint prettier

4
推荐指数
2
解决办法
5993
查看次数