diff --git a/js_modules/dagster-ui/packages/eslint-config/CHANGES.md b/js_modules/dagster-ui/packages/eslint-config/CHANGES.md index 6c7bf0ad4df36..55cc4b7682cda 100644 --- a/js_modules/dagster-ui/packages/eslint-config/CHANGES.md +++ b/js_modules/dagster-ui/packages/eslint-config/CHANGES.md @@ -1,3 +1,7 @@ +## 1.0.17 (September 3, 2024) + +- Added no-react-router-route rule. + ## 1.0.16 (August 28, 2024) - Added no-apollo-client rule. diff --git a/js_modules/dagster-ui/packages/eslint-config/package.json b/js_modules/dagster-ui/packages/eslint-config/package.json index 07aa391b88ef3..484d973aae9ff 100644 --- a/js_modules/dagster-ui/packages/eslint-config/package.json +++ b/js_modules/dagster-ui/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@dagster-io/eslint-config", - "version": "1.0.16", + "version": "1.0.17", "description": "Shared eslint configuration for @dagster-io", "license": "Apache-2.0", "main": "index.js", diff --git a/js_modules/dagster-ui/packages/eslint-config/rules/missing-graphql-variables-type.js b/js_modules/dagster-ui/packages/eslint-config/rules/missing-graphql-variables-type.js index af9e3f0d34579..977c1dd120332 100644 --- a/js_modules/dagster-ui/packages/eslint-config/rules/missing-graphql-variables-type.js +++ b/js_modules/dagster-ui/packages/eslint-config/rules/missing-graphql-variables-type.js @@ -17,13 +17,12 @@ const createRule = ESLintUtils.RuleCreator((name) => name); * */ -const APIS = new Set(['useQuery', 'useMutation', 'useSubscription']); -const APIToEnding = { - useQuery: 'Query', - useMutation: 'Mutation', - useSubscription: 'Subscription', - useLazyQuery: 'LazyQuery', -}; +const apisRequiringVariableType = new Set([ + 'useQuery', + 'useMutation', + 'useSubscription', + 'useLazyQuery', +]); module.exports = createRule({ create(context) { @@ -34,7 +33,7 @@ module.exports = createRule({ return; } // if it's not a useQuery call then ignore - if (!APIS.has(callee.name)) { + if (!apisRequiringVariableType.has(callee.name)) { return; } const API = callee.name; @@ -46,12 +45,18 @@ module.exports = createRule({ if (queryType.typeName.type !== 'Identifier') { return; } + const queryName = queryType.typeName.name; - // if the type doesn't end with Query then ignore - if (!queryName.endsWith(APIToEnding[API])) { + const variablesName = queryName + 'Variables'; + const secondType = node.typeParameters.params[1]; + if ( + secondType && + secondType.type === 'TSTypeReference' && + secondType.typeName.type === 'Identifier' && + secondType.typeName.name === variablesName + ) { return; } - const variablesName = queryName + 'Variables'; let queryImportSpecifier = null; const importDeclaration = context.getSourceCode().ast.body.find( (node) => @@ -63,48 +68,28 @@ module.exports = createRule({ } }), ); - const importPath = importDeclaration.source.value; - const currentPath = context.getFilename().split('/').slice(0, -1).join('/'); - const fullPath = path.join(currentPath, importPath + '.ts'); - - const graphqlTypeFile = fs.readFileSync(fullPath, {encoding: 'utf8'}); - - // This part is kind of hacky. I should use the parser service to find the identifier - // but this is faster then tokenizing the whole file - if ( - !graphqlTypeFile.includes('export type ' + variablesName) && - !graphqlTypeFile.includes('export interface ' + variablesName) - ) { + if (!importDeclaration) { return; } - // This is a Query type with a generated QueryVariables type. Make sure we're using it - const secondType = node.typeParameters.params[1]; - if ( - !secondType || - (secondType.type === 'TSTypeReference' && - secondType.typeName.type === 'Identifier' && - secondType.typeName.name !== variablesName) - ) { - context.report({ - messageId: 'missing-graphql-variables-type', - node, - data: { - queryType: queryName, - variablesType: variablesName, - api: API, - }, - *fix(fixer) { - if ( - !importDeclaration.specifiers.find( - (node) => node.type === 'ImportSpecifier' && node.local.name === variablesName, - ) - ) { - yield fixer.insertTextAfter(queryImportSpecifier, `, ${variablesName}`); - } - yield fixer.insertTextAfter(queryType, `, ${variablesName}`); - }, - }); - } + context.report({ + messageId: 'missing-graphql-variables-type', + node, + data: { + queryType: queryName, + variablesType: variablesName, + api: API, + }, + *fix(fixer) { + if ( + !importDeclaration.specifiers.find( + (node) => node.type === 'ImportSpecifier' && node.local.name === variablesName, + ) + ) { + yield fixer.insertTextAfter(queryImportSpecifier, `, ${variablesName}`); + } + yield fixer.insertTextAfter(queryType, `, ${variablesName}`); + }, + }); }, }; }, diff --git a/js_modules/dagster-ui/packages/eslint-config/rules/no-react-router-route.js b/js_modules/dagster-ui/packages/eslint-config/rules/no-react-router-route.js index 3de4f7c41624b..a4071f5890fa1 100644 --- a/js_modules/dagster-ui/packages/eslint-config/rules/no-react-router-route.js +++ b/js_modules/dagster-ui/packages/eslint-config/rules/no-react-router-route.js @@ -8,7 +8,6 @@ module.exports = createRule({ create(context) { return { [AST_NODE_TYPES.ImportDeclaration](node) { - console.log(context.getFilename()); if (context.getFilename().endsWith('/ui-core/src/app/Route.tsx')) { return; } @@ -37,9 +36,6 @@ module.exports = createRule({ const newImport = `import { Route } from '${relativeImportPath}';\n`; - const newImportRange = - routeSpecifier === node.specifiers[0] ? importRange : routeRange; - const fixes = []; if (node.specifiers.length === 1) { diff --git a/js_modules/dagster-ui/packages/ui-core/src/runs/RunsFilterInput.tsx b/js_modules/dagster-ui/packages/ui-core/src/runs/RunsFilterInput.tsx index 1443979bbdf1e..c308f18b3ee33 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/runs/RunsFilterInput.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/runs/RunsFilterInput.tsx @@ -12,6 +12,7 @@ import {useCallback, useMemo} from 'react'; import {DagsterTag} from './RunTag'; import { RunTagKeysQuery, + RunTagKeysQueryVariables, RunTagValuesQuery, RunTagValuesQueryVariables, } from './types/RunsFilterInput.types'; @@ -172,7 +173,10 @@ const tagsToExclude = [...CREATED_BY_TAGS, DagsterTag.Backfill, DagsterTag.Parti export const useRunsFilterInput = ({tokens, onChange, enabledFilters}: RunsFilterInputProps) => { const {options} = useRepositoryOptions(); - const [fetchTagKeys, {data: tagKeyData}] = useLazyQuery(RUN_TAG_KEYS_QUERY); + const [fetchTagKeys, {data: tagKeyData}] = useLazyQuery< + RunTagKeysQuery, + RunTagKeysQueryVariables + >(RUN_TAG_KEYS_QUERY); const client = useApolloClient(); const {UserDisplay} = useLaunchPadHooks();