Skip to content

Commit c4bf068

Browse files
authored
feat: Add tests for eslint plugin rules (#88)
* feat: Add example for ban-ts-comment rule * feat: Add example for no-explicit-any rule * feat: Add comment for no-console rule * feat: Add example for no explicit-function-return-type and no-console rules * feat: Add example for array-callback-return rule * feat: Add example for no-color-literals rule * feat: Add example for sort-styles rule * feat: Add example for no-raw-text rule * feat: Add example for no-unstable-nested-components rule * feat: Add example for react/prop-types if off * feat: Add example for react/no-unused-prop-types rule * feat: Add example for react/jsx-no-useless-fragment rule
1 parent d8d5289 commit c4bf068

8 files changed

Lines changed: 94 additions & 1 deletion
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This should trigger a warning because of array-callback-return rule
2+
const myArray = [1, 2, 3];
3+
const indexMap = myArray.reduce(function (acc, current) {
4+
acc = acc + current;
5+
}, 0);
6+
indexMap;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This should trigger a warning because of ban-ts-comment rule
2+
//@ts-ignore
3+
4+
//@ts-expect-error
5+
6+
//@ts-nocheck

example-app/eslint-breaking-examples/break-eslint-recommended-rules.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
"use strict";
44

5+
// This should trigger an error breaking no-console rule:
56
console.log(
6-
"This is a console.log statement to see it the linter produces an error"
7+
"This is a console.log statement to see if the linter produces an error"
78
);
89

910
// This should trigger two errors breaking eslint:recommended rules:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Text } from "react-native";
2+
3+
// Save without formatting: [⌘ + K] > [S]
4+
5+
// This should trigger an error because of jsx-no-useless-fragment rule
6+
const ComponentWithUselessFragment = () => {
7+
return (
8+
<>
9+
<Text>Useless text</Text>
10+
</>
11+
);
12+
};
13+
ComponentWithUselessFragment;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This should trigger an error because of no-explicit-any rule
2+
const explicitAnyTypedVariable: any = 0;
3+
explicitAnyTypedVariable;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This should trigger one error breaking no-unstable-nested-components:
2+
// react/no-unstable-nested-components
3+
4+
const MainComponent = () => {
5+
const NestedComponent = () => {
6+
return <View>Test</View>;
7+
};
8+
return <NestedComponent />;
9+
};
10+
MainComponent;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This should trigger one error breaking no-unused-prop-types:
2+
// react/no-unused-prop-types
3+
4+
import { Text } from "react-native";
5+
6+
interface NotUsedPropComponentProps {
7+
name: string;
8+
surname: string;
9+
}
10+
11+
const NotUsedPropComponent = (props: NotUsedPropComponentProps) => {
12+
return <Text>{`Hello ${props.name} I refuse to use the surname prop`}</Text>;
13+
};
14+
NotUsedPropComponent;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { StyleSheet, Text, View } from "react-native";
2+
3+
// This should not trigger a warning nor an error because explicit-function-return-type rule is off
4+
const noReturnTypeDefined = () => {
5+
return;
6+
};
7+
noReturnTypeDefined();
8+
9+
// These should not trigger a warning nor an error because no-console rule is off for warns and errors
10+
console.warn("This is a warning message");
11+
console.error("This is an error message");
12+
13+
// This should not trigger a warning nor an error because no-color-literals rule is off
14+
const styles = StyleSheet.create({
15+
view: {
16+
color: "red",
17+
},
18+
});
19+
styles.view;
20+
21+
// This should not trigger a warning nor an error because sort-styles rule is off
22+
const notSortedStyles = StyleSheet.create({
23+
beta: {},
24+
alpha: {},
25+
});
26+
notSortedStyles.alpha;
27+
notSortedStyles.beta;
28+
29+
// This should not trigger an error because no-raw-text rule is off
30+
31+
export const MyText = () => {
32+
return <View>Test</View>;
33+
};
34+
35+
// This should not trigger an error because react/prop-types rule is off
36+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
37+
// @ts-ignore
38+
export const ComponentWithNotTypedProps = ({ name }) => {
39+
return <Text>{name}</Text>;
40+
};

0 commit comments

Comments
 (0)