Skip to content

Commit

Permalink
chore: allow babel in tc
Browse files Browse the repository at this point in the history
  • Loading branch information
akulsr0 committed Aug 15, 2023
1 parent f7447b7 commit c984b4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 23 additions & 0 deletions lib/rules/sort-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ module.exports = {
const typeAnnotations = new Map();

function getKey(node) {
if (node.type === 'ObjectTypeProperty') {
return context.getSourceCode().getFirstToken(node).value;
}
if (node.key && node.key.value) {
return node.key.value;
}
Expand Down Expand Up @@ -236,6 +239,16 @@ module.exports = {
if (firstArg.members) {
checkSorted(firstArg.members);

Check warning on line 240 in lib/rules/sort-prop-types.js

View check run for this annotation

Codecov / codecov/patch

lib/rules/sort-prop-types.js#L239-L240

Added lines #L239 - L240 were not covered by tests
}
} else if (firstArg && firstArg.type === 'GenericTypeAnnotation') {
const propType = typeAnnotations.get(firstArg.id.name)
&& typeAnnotations.get(firstArg.id.name)[0];
if (propType && propType.properties) {
checkSorted(propType.properties);
}
} else if (firstArg && firstArg.type === 'ObjectTypeAnnotation') {
if (firstArg.properties) {
checkSorted(firstArg.properties);
}
}
}

Expand Down Expand Up @@ -296,6 +309,16 @@ module.exports = {
}
},

TypeAlias(node) {
if (node.right.type === 'ObjectTypeAnnotation') {
const currentNode = [].concat(
typeAnnotations.get(node.id.name) || [],
node.right
);
typeAnnotations.set(node.id.name, currentNode);
}
},

TSTypeAliasDeclaration(node) {
if (node.typeAnnotation.type === 'TSTypeLiteral' || node.typeAnnotation.type === 'ObjectTypeAnnotation') {
const currentNode = [].concat(
Expand Down
9 changes: 3 additions & 6 deletions tests/lib/rules/sort-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2283,14 +2283,13 @@ ruleTester.run('sort-prop-types', rule, {
return null;
}
`,
features: ['ts', 'no-babel'],
features: ['types'],
options: [{ checkTypes: true }],
errors: [
{
messageId: 'propsNotSorted',
line: 4,
column: 11,
type: 'TSPropertySignature',
},
],
},
Expand All @@ -2313,14 +2312,13 @@ ruleTester.run('sort-prop-types', rule, {
return null;
}
`,
features: ['ts', 'no-babel'],
features: ['types'],
options: [{ checkTypes: true }],
errors: [
{
messageId: 'propsNotSorted',
line: 4,
column: 11,
type: 'TSPropertySignature',
},
],
},
Expand All @@ -2341,14 +2339,13 @@ ruleTester.run('sort-prop-types', rule, {
return null;
}
`,
features: ['ts', 'no-babel'],
features: ['types'],
options: [{ checkTypes: true }],
errors: [
{
messageId: 'propsNotSorted',
line: 4,
column: 11,
type: 'TSPropertySignature',
},
],
}
Expand Down

0 comments on commit c984b4f

Please sign in to comment.