Skip to content

Commit

Permalink
Use TS and JSX shared configs from eslint-config-hypothesis
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 18, 2024
1 parent 3b0789e commit fb263f1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 44 deletions.
40 changes: 8 additions & 32 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
import hypothesis from 'eslint-config-hypothesis';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import hypothesisBase from 'eslint-config-hypothesis/base';
import hypothesisJSX from 'eslint-config-hypothesis/jsx';
import hypothesisTS from 'eslint-config-hypothesis/ts';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
export default [
{
ignores: ['.yalc/**', 'lib/**', 'build/**'],
},
...hypothesis,
...tseslint.configs.recommended,
jsxA11y.flatConfigs.recommended,
{
rules: {
// Replaced by TypeScript's static checking.
'react/prop-types': 'off',
// Upgrade TS rules from warning to error.
'@typescript-eslint/no-unused-vars': 'error',

// Disable TS rules that we dislike.
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-this-alias': 'off',

// Enforce consistency in cases where TypeScript supports old and new
// syntaxes for the same thing.
//
// - Require `<var> as <type>` for casts
// - Require `import type` for type imports. The corresponding rule for
// exports is not enabled yet because that requires setting up
// type-aware linting.
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
},
},
...hypothesisBase,
...hypothesisJSX,
...hypothesisTS,

// Icons
{
Expand All @@ -56,4 +32,4 @@ export default tseslint.config(
},
},
},
);
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"enzyme": "^3.8.0",
"enzyme-adapter-preact-pure": "^4.0.1",
"eslint": "^9.12.0",
"eslint-config-hypothesis": "^3.0.0",
"eslint-config-hypothesis": "^3.1.0",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-react": "^7.37.1",
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function generateIconIndex(componentDir) {
file => file.endsWith('.tsx') && !file.includes('index'),
);
let outputSrc = `${AUTO_GENERATED_COMMENT}\n`;
for (let componentFile of iconComponents) {
for (const componentFile of iconComponents) {
const componentModule = path.basename(componentFile, '.tsx');
const componentName = `${componentModule}Icon`;
outputSrc += `export { default as ${componentName} } from './${componentModule}';\n`;
Expand All @@ -133,7 +133,7 @@ const inputDir = argv[2] ?? 'images/icons';
const outputDir = argv[3] ?? 'src/components/icons';

const svgFiles = readdirSync(inputDir).filter(file => file.endsWith('.svg'));
for (let file of svgFiles) {
for (const file of svgFiles) {
await generateIconFromFile(`${inputDir}/${file}`, outputDir);
}

Expand Down
2 changes: 2 additions & 0 deletions src/components/input/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ function SelectMain<T>({
}

export const Select = Object.assign(
// eslint-disable-next-line prefer-arrow-callback
function <T>(props: SelectProps<T>) {
// Calling the function directly instead of returning a JSX element, to
// avoid an unnecessary extra layer in the component tree
Expand All @@ -598,6 +599,7 @@ export const Select = Object.assign(
);

export const MultiSelect = Object.assign(
// eslint-disable-next-line prefer-arrow-callback
function <T>(props: MultiSelectProps<T>) {
// Calling the function directly instead of returning a JSX element, to
// avoid an unnecessary extra layer in the component tree
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/test/use-arrow-key-navigation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ describe('useArrowKeyNavigation', () => {
['Home', 'Bold'],
];

for (let [key, expectedItem] of steps) {
for (const [key, expectedItem] of steps) {
pressKey(key);

const currentElement = document.activeElement;
assert.equal(currentElement.innerText, expectedItem);

const toolbarButtons = toolbar.querySelectorAll('a,button');
for (let element of toolbarButtons) {
for (const element of toolbarButtons) {
if (element === currentElement) {
assert.equal(element.tabIndex, 0);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/test/use-tab-key-navigation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ describe('useTabKeyNavigation', () => {
[backKey, 'Bold'],
];

for (let [key, expectedItem] of steps) {
for (const [key, expectedItem] of steps) {
pressKey(key);

const currentElement = document.activeElement;
assert.equal(currentElement.innerText, expectedItem);

const toolbarButtons = toolbar.querySelectorAll('a,button');
for (let element of toolbarButtons) {
for (const element of toolbarButtons) {
if (element === currentElement) {
assert.equal(element.tabIndex, 0);
} else {
Expand Down
22 changes: 17 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ __metadata:
enzyme: ^3.8.0
enzyme-adapter-preact-pure: ^4.0.1
eslint: ^9.12.0
eslint-config-hypothesis: ^3.0.0
eslint-config-hypothesis: ^3.1.0
eslint-plugin-jsx-a11y: ^6.10.0
eslint-plugin-mocha: ^10.5.0
eslint-plugin-react: ^7.37.1
Expand Down Expand Up @@ -5171,14 +5171,26 @@ __metadata:
languageName: node
linkType: hard

"eslint-config-hypothesis@npm:^3.0.0":
version: 3.0.0
resolution: "eslint-config-hypothesis@npm:3.0.0"
"eslint-config-hypothesis@npm:^3.1.0":
version: 3.1.0
resolution: "eslint-config-hypothesis@npm:3.1.0"
peerDependencies:
eslint-plugin-jsx-a11y: ">=6.10.0"
eslint-plugin-mocha: ">=10.4.0"
eslint-plugin-react: ">=7.34.0"
eslint-plugin-react-hooks: ">=5.0.0"
checksum: 1194156f2d043ed866afe9ccd88d7364cdf8635cb9d762d24beffb03ee02a25d44081b58d95c5b1a658e686053948d8b2493e65f4de540e14d72ae83c35c31fe
globals: ">=15.11.0"
typescript-eslint: ">=8.10.0"
peerDependenciesMeta:
eslint-plugin-jsx-a11y:
optional: true
eslint-plugin-react:
optional: true
eslint-plugin-react-hooks:
optional: true
typescript-eslint:
optional: true
checksum: 12e17da643a306fec1c8121bf5f172f2132f816d85b2b6f626dc16d353f5cbac8bee0cce080a9df829c5eab3e4bcc007bb611ec6f5d9deebd627e530802c05f6
languageName: node
linkType: hard

Expand Down

0 comments on commit fb263f1

Please sign in to comment.