From e839eaaa93e12f70fb844a7d0067ce087b3a6f10 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Tue, 14 Dec 2021 14:23:25 -0800 Subject: [PATCH] eslint-plugin: classify stories as examples not tests (#20681) --- ...-5733e325-0c8b-4b50-ad12-d52a70e3d28b.json | 7 +++++++ packages/eslint-plugin/src/configs/react.js | 12 +++++++++++- .../eslint-plugin/src/utils/configHelpers.js | 19 +++++++++++++------ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 change/@fluentui-eslint-plugin-5733e325-0c8b-4b50-ad12-d52a70e3d28b.json diff --git a/change/@fluentui-eslint-plugin-5733e325-0c8b-4b50-ad12-d52a70e3d28b.json b/change/@fluentui-eslint-plugin-5733e325-0c8b-4b50-ad12-d52a70e3d28b.json new file mode 100644 index 0000000000000..ba984fd5ce00e --- /dev/null +++ b/change/@fluentui-eslint-plugin-5733e325-0c8b-4b50-ad12-d52a70e3d28b.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Classify .stories.tsx as examples not tests", + "packageName": "@fluentui/eslint-plugin", + "email": "elcraig@microsoft.com", + "dependentChangeType": "none" +} diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index 697f4e4ab4507..984800edbf887 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -374,12 +374,22 @@ const getOverrides = () => [ }, { // Example overrides - files: '**/*.Example.tsx', + files: '**/*.{Example,stories}.tsx', rules: { 'no-alert': 'off', 'no-console': 'off', }, }, + { + files: '**/*.stories.tsx', + rules: { + // allow arrow functions in stories for now (may want to change this later since using + // constantly-mutating functions can be an anti-pattern which we may not want to demonstrate + // in our converged components docs; it happened to be allowed starting out because .stories + // files were being linted as tests) + 'react/jsx-no-bind': 'off', + }, + }, { // Docs overrides (excluding examples) files: [...configHelpers.docsFiles], diff --git a/packages/eslint-plugin/src/utils/configHelpers.js b/packages/eslint-plugin/src/utils/configHelpers.js index 2f907386e6066..1c6ee4e01454e 100644 --- a/packages/eslint-plugin/src/utils/configHelpers.js +++ b/packages/eslint-plugin/src/utils/configHelpers.js @@ -5,11 +5,10 @@ const path = require('path'); const jju = require('jju'); const testFiles = [ - '**/*{.,-}test.{ts,tsx}', - '**/*.stories.tsx', - '**/{common,test,tests,stories}/**', + '**/*{.,-}{test,spec}.{ts,tsx}', + '**/{test,tests}/**', '**/testUtilities.{ts,tsx}', - '**/common/isConformant.{ts,tsx}', + '**/common/{isConformant,snapshotSerializers}.{ts,tsx}', ]; const docsFiles = ['**/*Page.tsx', '**/{docs,demo}/**', '**/*.doc.{ts,tsx}']; @@ -47,8 +46,16 @@ module.exports = { /** Files for build configuration */ configFiles, - /** Files which may reference devDependencies: tests, docs (excluding examples), config/build */ - devDependenciesFiles: [...testFiles, ...docsFiles, ...configFiles], + /** + * Files which may reference `devDependencies`: + * - tests + * - docs (excluding v8 examples) + * - config/build + * - stories, for now + * - may need to reconsider for converged components depending on website approach + * - the stories suffix is also used for screener stories in `vr-tests` + */ + devDependenciesFiles: [...testFiles, ...docsFiles, ...configFiles, '**/*.stories.tsx'], /** * Whether linting is running in context of lint-staged (which should disable rules requiring