Skip to content

Commit

Permalink
Lint/Format all the snack examples (#3422)
Browse files Browse the repository at this point in the history
* Lint/Format all the examples

This adds a script which can run ESLint on each Snack example in Markdown. This is wired to the default RN ESLint configuration, and a Prettier configuration to limit to 70 lines to prevent wrapping. Apart from snforcing consistency, it means copy/pasting examples into a new RN project will not create formatting errors.

Not all examples are clean of lint errors/warnings so this is not enforced yet. The script is also currently very slow. But it's a good start, and we can later apply something similar to `tsc`.

* Remove package-local gitignore

* Remove deps

* Fix for Windows

* let lint:examples lint the example code
  • Loading branch information
NickGerleman authored Dec 1, 2022
1 parent d926b9e commit e86aebe
Show file tree
Hide file tree
Showing 91 changed files with 6,186 additions and 3,129 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ website/build/

sync-api-docs/generatedComponentApiDocs.js
sync-api-docs/extracted.json

scripts/lint-examples/out/
58 changes: 27 additions & 31 deletions docs/accessibilityinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,33 @@ Sometimes it's useful to know whether or not the device has a screen reader that
<TabItem value="functional">

```SnackPlayer name=AccessibilityInfo%20Function%20Component%20Example&supportedPlatforms=android,ios
import React, { useState, useEffect } from "react";
import { AccessibilityInfo, View, Text, StyleSheet } from "react-native";
import React, {useState, useEffect} from 'react';
import {AccessibilityInfo, View, Text, StyleSheet} from 'react-native';
const App = () => {
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false);
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false);
useEffect(() => {
const reduceMotionChangedSubscription = AccessibilityInfo.addEventListener(
"reduceMotionChanged",
'reduceMotionChanged',
reduceMotionEnabled => {
setReduceMotionEnabled(reduceMotionEnabled);
}
},
);
const screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
"screenReaderChanged",
'screenReaderChanged',
screenReaderEnabled => {
setScreenReaderEnabled(screenReaderEnabled);
}
},
);
AccessibilityInfo.isReduceMotionEnabled().then(
reduceMotionEnabled => {
setReduceMotionEnabled(reduceMotionEnabled);
}
);
AccessibilityInfo.isScreenReaderEnabled().then(
screenReaderEnabled => {
setScreenReaderEnabled(screenReaderEnabled);
}
);
AccessibilityInfo.isReduceMotionEnabled().then(reduceMotionEnabled => {
setReduceMotionEnabled(reduceMotionEnabled);
});
AccessibilityInfo.isScreenReaderEnabled().then(screenReaderEnabled => {
setScreenReaderEnabled(screenReaderEnabled);
});
return () => {
reduceMotionChangedSubscription.remove();
Expand All @@ -54,24 +50,24 @@ const App = () => {
return (
<View style={styles.container}>
<Text style={styles.status}>
The reduce motion is {reduceMotionEnabled ? "enabled" : "disabled"}.
The reduce motion is {reduceMotionEnabled ? 'enabled' : 'disabled'}.
</Text>
<Text style={styles.status}>
The screen reader is {screenReaderEnabled ? "enabled" : "disabled"}.
The screen reader is {screenReaderEnabled ? 'enabled' : 'disabled'}.
</Text>
</View>
);
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center"
alignItems: 'center',
justifyContent: 'center',
},
status: {
margin: 30
}
margin: 30,
},
});
export default App;
Expand All @@ -81,8 +77,8 @@ export default App;
<TabItem value="classical">

```SnackPlayer name=AccessibilityInfo%20Class%20Component%20Example&supportedPlatforms=android,ios
import React, { Component } from 'react';
import { AccessibilityInfo, View, Text, StyleSheet } from 'react-native';
import React, {Component} from 'react';
import {AccessibilityInfo, View, Text, StyleSheet} from 'react-native';
class AccessibilityStatusExample extends Component {
state = {
Expand All @@ -94,21 +90,21 @@ class AccessibilityStatusExample extends Component {
this.reduceMotionChangedSubscription = AccessibilityInfo.addEventListener(
'reduceMotionChanged',
reduceMotionEnabled => {
this.setState({ reduceMotionEnabled });
}
this.setState({reduceMotionEnabled});
},
);
this.screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
'screenReaderChanged',
screenReaderEnabled => {
this.setState({ screenReaderEnabled });
}
this.setState({screenReaderEnabled});
},
);
AccessibilityInfo.isReduceMotionEnabled().then(reduceMotionEnabled => {
this.setState({ reduceMotionEnabled });
this.setState({reduceMotionEnabled});
});
AccessibilityInfo.isScreenReaderEnabled().then(screenReaderEnabled => {
this.setState({ screenReaderEnabled });
this.setState({screenReaderEnabled});
});
}
Expand Down
20 changes: 10 additions & 10 deletions docs/actionsheetios.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ Displays native to iOS [Action Sheet](https://developer.apple.com/design/human-i
## Example

```SnackPlayer name=ActionSheetIOS&supportedPlatforms=ios
import React, { useState } from "react";
import { ActionSheetIOS, Button, StyleSheet, Text, View } from "react-native";
import React, {useState} from 'react';
import {ActionSheetIOS, Button, StyleSheet, Text, View} from 'react-native';
const App = () => {
const [result, setResult] = useState("🔮");
const [result, setResult] = useState('🔮');
const onPress = () =>
ActionSheetIOS.showActionSheetWithOptions(
{
options: ["Cancel", "Generate number", "Reset"],
options: ['Cancel', 'Generate number', 'Reset'],
destructiveButtonIndex: 2,
cancelButtonIndex: 0,
userInterfaceStyle: 'dark'
userInterfaceStyle: 'dark',
},
buttonIndex => {
if (buttonIndex === 0) {
// cancel action
} else if (buttonIndex === 1) {
setResult(Math.floor(Math.random() * 100) + 1);
} else if (buttonIndex === 2) {
setResult("🔮");
setResult('🔮');
}
}
},
);
return (
Expand All @@ -44,12 +44,12 @@ const App = () => {
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center"
justifyContent: 'center',
},
result: {
fontSize: 64,
textAlign: "center"
}
textAlign: 'center',
},
});
export default App;
Expand Down
28 changes: 14 additions & 14 deletions docs/activityindicator.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Displays a circular loading indicator.
<TabItem value="functional">

```SnackPlayer name=ActivityIndicator%20Function%20Component%20Example
import React from "react";
import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
import React from 'react';
import {ActivityIndicator, StyleSheet, Text, View} from 'react-native';
const App = () => (
<View style={[styles.container, styles.horizontal]}>
Expand All @@ -28,13 +28,13 @@ const App = () => (
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center"
justifyContent: 'center',
},
horizontal: {
flexDirection: "row",
justifyContent: "space-around",
padding: 10
}
flexDirection: 'row',
justifyContent: 'space-around',
padding: 10,
},
});
export default App;
Expand All @@ -44,8 +44,8 @@ export default App;
<TabItem value="classical">

```SnackPlayer name=ActivityIndicator%20Class%20Component%20Example
import React, { Component } from "react";
import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
import React, {Component} from 'react';
import {ActivityIndicator, StyleSheet, Text, View} from 'react-native';
class App extends Component {
render() {
Expand All @@ -63,13 +63,13 @@ class App extends Component {
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center"
justifyContent: 'center',
},
horizontal: {
flexDirection: "row",
justifyContent: "space-around",
padding: 10
}
flexDirection: 'row',
justifyContent: 'space-around',
padding: 10,
},
});
export default App;
Expand Down
Loading

0 comments on commit e86aebe

Please sign in to comment.