Skip to content

Commit

Permalink
Update eslint version (#24184)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Updated eslint version + remove some unnecessary logic in
missing-graphql-variables logic.

## How I Tested These Changes

existing jest test

## Changelog [New | Bug | Docs]
NOCHANGELOG

---------

Co-authored-by: Marco Salazar <[email protected]>
  • Loading branch information
salazarm and salazarm authored Sep 3, 2024
1 parent d8d3c48 commit f79a36b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 57 deletions.
4 changes: 4 additions & 0 deletions js_modules/dagster-ui/packages/eslint-config/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion js_modules/dagster-ui/packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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) =>
Expand All @@ -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}`);
},
});
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {useCallback, useMemo} from 'react';
import {DagsterTag} from './RunTag';
import {
RunTagKeysQuery,
RunTagKeysQueryVariables,
RunTagValuesQuery,
RunTagValuesQueryVariables,
} from './types/RunsFilterInput.types';
Expand Down Expand Up @@ -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<RunTagKeysQuery>(RUN_TAG_KEYS_QUERY);
const [fetchTagKeys, {data: tagKeyData}] = useLazyQuery<
RunTagKeysQuery,
RunTagKeysQueryVariables
>(RUN_TAG_KEYS_QUERY);
const client = useApolloClient();
const {UserDisplay} = useLaunchPadHooks();

Expand Down

1 comment on commit f79a36b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-3l0dcwgq9-elementl.vercel.app

Built with commit f79a36b.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.