path
stringlengths 5
296
| repo_name
stringlengths 5
85
| content
stringlengths 25
1.05M
|
|---|---|---|
packages/zensroom/lib/components/static/About.js
|
SachaG/Zensroom
|
/*
About page.
*/
import React from 'react';
import { Components, registerComponent } from 'meteor/vulcan:core';
const About = () =>
<div>
About
</div>
registerComponent('About', About);
export default About;
|
node_modules/react-router/es/Router.js
|
raptor1989/MobileHeader
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import invariant from 'invariant';
import React from 'react';
import createReactClass from 'create-react-class';
import { func, object } from 'prop-types';
import _createTransitionManager from './createTransitionManager';
import { routes } from './InternalPropTypes';
import RouterContext from './RouterContext';
import { createRoutes } from './RouteUtils';
import { createRouterObject as _createRouterObject, assignRouterState } from './RouterUtils';
import warning from './routerWarning';
var propTypes = {
history: object,
children: routes,
routes: routes, // alias for children
render: func,
createElement: func,
onError: func,
onUpdate: func,
// PRIVATE: For client-side rehydration of server match.
matchContext: object
};
/**
* A <Router> is a high-level API for automatically setting up
* a router that renders a <RouterContext> with all the props
* it needs each time the URL changes.
*/
var Router = createReactClass({
displayName: 'Router',
propTypes: propTypes,
getDefaultProps: function getDefaultProps() {
return {
render: function render(props) {
return React.createElement(RouterContext, props);
}
};
},
getInitialState: function getInitialState() {
return {
location: null,
routes: null,
params: null,
components: null
};
},
handleError: function handleError(error) {
if (this.props.onError) {
this.props.onError.call(this, error);
} else {
// Throw errors by default so we don't silently swallow them!
throw error; // This error probably occurred in getChildRoutes or getComponents.
}
},
createRouterObject: function createRouterObject(state) {
var matchContext = this.props.matchContext;
if (matchContext) {
return matchContext.router;
}
var history = this.props.history;
return _createRouterObject(history, this.transitionManager, state);
},
createTransitionManager: function createTransitionManager() {
var matchContext = this.props.matchContext;
if (matchContext) {
return matchContext.transitionManager;
}
var history = this.props.history;
var _props = this.props,
routes = _props.routes,
children = _props.children;
!history.getCurrentLocation ? process.env.NODE_ENV !== 'production' ? invariant(false, 'You have provided a history object created with history v4.x or v2.x ' + 'and earlier. This version of React Router is only compatible with v3 ' + 'history objects. Please change to history v3.x.') : invariant(false) : void 0;
return _createTransitionManager(history, createRoutes(routes || children));
},
componentWillMount: function componentWillMount() {
var _this = this;
this.transitionManager = this.createTransitionManager();
this.router = this.createRouterObject(this.state);
this._unlisten = this.transitionManager.listen(function (error, state) {
if (error) {
_this.handleError(error);
} else {
// Keep the identity of this.router because of a caveat in ContextUtils:
// they only work if the object identity is preserved.
assignRouterState(_this.router, state);
_this.setState(state, _this.props.onUpdate);
}
});
},
/* istanbul ignore next: sanity check */
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
process.env.NODE_ENV !== 'production' ? warning(nextProps.history === this.props.history, 'You cannot change <Router history>; it will be ignored') : void 0;
process.env.NODE_ENV !== 'production' ? warning((nextProps.routes || nextProps.children) === (this.props.routes || this.props.children), 'You cannot change <Router routes>; it will be ignored') : void 0;
},
componentWillUnmount: function componentWillUnmount() {
if (this._unlisten) this._unlisten();
},
render: function render() {
var _state = this.state,
location = _state.location,
routes = _state.routes,
params = _state.params,
components = _state.components;
var _props2 = this.props,
createElement = _props2.createElement,
render = _props2.render,
props = _objectWithoutProperties(_props2, ['createElement', 'render']);
if (location == null) return null; // Async match
// Only forward non-Router-specific props to routing context, as those are
// the only ones that might be custom routing context props.
Object.keys(propTypes).forEach(function (propType) {
return delete props[propType];
});
return render(_extends({}, props, {
router: this.router,
location: location,
routes: routes,
params: params,
components: components,
createElement: createElement
}));
}
});
export default Router;
|
app/containers/EnergiesPage/Input.js
|
mhoffman/CatAppBrowser
|
/*
*
* EnergiesPageInput
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import styled from 'styled-components';
import ReactGA from 'react-ga';
import Button from 'material-ui/Button';
import { LinearProgress, CircularProgress } from 'material-ui/Progress';
import Paper from 'material-ui/Paper';
import { withStyles } from 'material-ui/styles';
import Grid from 'material-ui/Grid';
import { FormGroup } from 'material-ui/Form';
import * as Scroll from 'react-scroll';
import { MdSearch, MdWarning } from 'react-icons/lib/md';
import cachios from 'cachios';
import { newGraphQLRoot } from 'utils/constants';
import { withCommas } from 'utils/functions';
import * as actions from './actions';
import TermAutosuggest from './TermAutosuggest';
const MButton = styled(Button)`
margin: 25px;
marginLeft: 0;
`;
const styles = (theme) => ({
paper: {
padding: theme.spacing.unit * 2,
marginTop: theme.spacing.unit * 3,
},
button: {
margin: theme.spacing.unit,
textTransform: 'none',
},
progress: {
margin: theme.spacing.unit,
},
hint: {
color: '#aaa',
marginBottom: theme.spacing.unit,
},
});
const initialState = {
reactant_options: [],
product_options: [],
facet: '',
surfaceComposition: '',
reactants: { label: 'any', value: '' },
products: { label: 'any', value: '' },
loading: false,
suggestionsReady: false,
resultCount: '...',
};
class EnergiesPageInput extends React.Component { // eslint-disable-line react/prefer-stateless-function
constructor(props) {
super(props);
this.state = initialState;
// Workaround, instead of calling .bind in every render
this.submitForm = this.submitForm.bind(this);
this.resetForm = this.resetForm.bind(this);
this.setSubstate = this.setSubstate.bind(this);
this.getFilterString = this.getFilterString.bind(this);
this.getResultCount = this.getResultCount.bind(this);
this.getResultCount();
}
componentDidMount() {
this.updateOptions();
this.getResultCount();
}
setSubstate(key, value) {
const newSubstate = {};
newSubstate[key] = value;
this.setState(newSubstate);
}
getResultCount() {
this.setState({
resultCount: <CircularProgress size={25} />,
});
const filterString = this.getFilterString();
const query = {
ttl: 300,
query: `query{reactions ( first: 0, ${filterString} ) {
totalCount
edges {
node {
id
}
}
}}
` };
cachios.post(newGraphQLRoot, query).then((response) => {
const totalCount = response.data.data.reactions.totalCount;
let message;
if (totalCount === 0) {
message = <div>No entries <MdWarning /></div>;
} else if (totalCount === 1) {
message = '1 entry';
} else {
message = `${withCommas(response.data.data.reactions.totalCount)} entries`;
}
this.setState({
resultCount: message,
});
});
}
getFilterString() {
const filters = [];
if (typeof this.state.surfaceComposition.label !== 'undefined' && this.state.surfaceComposition.label) {
filters.push(`surfaceComposition: "${this.state.surfaceComposition.label.trim()}"`);
}
if (typeof this.state.facet.label !== 'undefined' && this.state.facet.label) {
filters.push(`facet: "~${this.state.facet.label.replace(/^\(([^)]*)\)$/, '$1').trim()}"`);
}
if (typeof this.state.reactants.label !== 'undefined' && this.state.reactants.label) {
filters.push(`reactants: "${this.state.reactants.label.replace(/\*/g, 'star').replace(/[ ]/g, '').replace('any', '').trim() || '~'}"`);
}
if (typeof this.state.products.label !== 'undefined' && this.state.products.label) {
filters.push(`products: "${this.state.products.label.replace(/\*/g, 'star').replace(/[ ]/g, '').replace('any', '').trim() || '~'}"`);
}
const filterString = filters.join(', ');
return filterString;
}
handleChange(name) {
return (event) => {
this.setState({
[name]: event.target.value,
});
this.updateOptions(name);
};
}
resetForm() {
this.setState(initialState);
this.updateOptions('');
this.props.receiveReactions([]);
this.props.clearSystems();
}
submitForm() {
this.props.clearSystems();
this.setState({ loading: true });
const filterString = this.getFilterString();
this.props.saveSearch(filterString);
ReactGA.event({
category: 'Search',
action: 'Search',
label: filterString,
});
const query = {
ttl: 300,
query: `query{reactions ( first: 200, ${filterString} ) {
totalCount
edges {
node {
Equation
sites
id
pubId
dftCode
dftFunctional
reactants
products
facet
chemicalComposition
facet
reactionEnergy
activationEnergy
surfaceComposition
chemicalComposition
reactionSystems {
name
energyCorrection
aseId
}
}
}
}}`,
};
cachios.post(newGraphQLRoot, query).then((response) => {
Scroll.animateScroll.scrollMore(500);
this.setState({
loading: false,
});
this.props.saveSearchQuery(query.query);
this.props.submitSearch({
reactants: this.state.reactants.label,
products: this.state.products.label,
surfaceComposition: this.state.surfaceComposition.label,
facet: this.state.facet.label,
});
this.props.receiveReactions(response.data.data.reactions.edges);
this.props.saveResultSize(response.data.data.reactions.totalCount);
}).catch(() => {
this.setState({
loading: false,
});
});
}
updateOptions(blocked = '') {
let query = '';
// Fetch Available Reactants
if (blocked !== 'reactants' && this.state.reactants.label === 'any') {
query = `{reactions(products: "~${this.state.products.value || ''}", reactants: "~", distinct: true) { edges { node { reactants } } }}`;
cachios.post(newGraphQLRoot, {
query,
ttl: 300,
}).then((response) => {
let reactants = [];
const reactant = (response.data.data.reactions.edges.map((elem) => JSON.parse(elem.node.reactants)));
reactants = reactant.map((r) => ({ key: Object.keys(r).join(' + '), value: Object.keys(r).join(' + ') }));
reactants.push({ label: 'any', value: '' });
this.setState({
reactant_options: [...new Set(reactants)],
suggestionsReady: true,
});
}).catch((error) => {
this.props.setDbError(error);
});
}
// Fetch Available Products
if (blocked !== 'products' && this.state.products.label === 'any') {
query = `{reactions(reactants: "~${this.state.reactants.value || ''}", products: "~", distinct: true) { edges { node { products } } }}`;
cachios.post(newGraphQLRoot, {
query,
ttl: 300,
}).then((response) => {
let products = [];
const product = (response.data.data.reactions.edges.map((elem) => JSON.parse(elem.node.products)));
products = products.concat([].concat(...product));
products = product.map((r) => ({ key: Object.keys(r).join(' + '), value: Object.keys(r).join(' + ') }));
/* products = products.map((r) => ({ value: r, label: r.replace('star', '*') }));*/
products.push({ label: 'any', value: '' });
this.setState({
product_options: [...new Set(products)],
suggestionsReady: true,
}).catch(() => {
this.props.setDbError();
});
});
}
}
render() {
return (
<Paper className={this.props.classes.paper}>
{this.props.dbError ? <div><MdWarning />Failed to contact database. </div> : null }
<h2>Surface Reactions</h2>
<h3>Search for chemical reactions across all publications and datasets!</h3>
<div style={{ width: '55%', textAlign: 'justify' }}>
<div> A quick guide: </div>
<ul>
<li> Leave fields blank if you {"don't"} want to impose any restrictions. </li>
<li> For the <b>Reactants</b> and <b>Products</b> fields, choose the chemical species taking part in the left- and/or right hand side of the chemical reaction respectively. The phase of the molecules and elements can also be specified, such that {"'CO2gas'"} refers to CO<sub>2</sub> in the gas phase, whereas {"'CO2*'"} refers to CO<sub>2</sub> adsorbed on the surface. </li>
<li> In the <b>Surface</b> field, enter the (reduced) chemical composition of the surface, or a sum of elements that must be present, such as {"'Ag+'"} or {"'Ag+Sr'"}. </li>
</ul>
</div>
<div className={this.props.classes.hint}>{this.state.resultCount}</div>
<FormGroup row>
<TermAutosuggest field="reactants" setSubstate={this.setSubstate} submitForm={this.submitForm} label="Reactants" placeholder="CO, CO*, COgas, ..." autofocus initialValue={this.props.filter.reactants} keyUp={this.getResultCount} />
<span style={{ flexGrow: 1, position: 'relative', float: 'left', display: 'inline-block', whiteSpace: 'nowrap', margin: 10 }} > {'→'} </span>
<TermAutosuggest field="products" submitForm={this.submitForm} setSubstate={this.setSubstate} label="Products" placeholder="" initialValue={this.props.filter.products} keyUp={this.getResultCount} />
<span style={{ flexGrow: 1, position: 'relative', float: 'left', display: 'inline-block', whiteSpace: 'nowrap', margin: 10 }} > {' '} </span>
<TermAutosuggest field="surfaceComposition" submitForm={this.submitForm} setSubstate={this.setSubstate} label="Surface" placeholder="Pt, CoO3, ..." initialValue={this.props.filter.surfaceComposition} keyUp={this.getResultCount} />
<span style={{ flexGrow: 1, position: 'relative', float: 'left', display: 'inline-block', whiteSpace: 'nowrap', margin: 10 }} > {' '} </span>
<TermAutosuggest field="facet" submitForm={this.submitForm} setSubstate={this.setSubstate} label="Facet" placeholder="100, 111-(4x4) 10-14, ..." initialValue={this.props.filter.facet} keyUp={this.getResultCount} />
<span style={{ flexGrow: 1, position: 'relative', float: 'left', display: 'inline-block', whiteSpace: 'nowrap', margin: 10 }} > {' '} </span>
<br />
<br />
<Grid container justify="flex-end" direction="row">
<Grid item>
<MButton raised onClick={this.submitForm} color="primary" className={this.props.classes.button}><MdSearch /> Search </MButton>
</Grid>
</Grid>
</FormGroup>
{this.state.loading ? <LinearProgress color="primary" className={this.props.classes.progress} /> :
null
}
</Paper>
);
}
}
EnergiesPageInput.propTypes = {
classes: PropTypes.object,
clearSystems: PropTypes.func.isRequired,
dbError: PropTypes.bool,
filter: PropTypes.object,
receiveReactions: PropTypes.func.isRequired,
saveResultSize: PropTypes.func,
saveSearch: PropTypes.func,
submitSearch: PropTypes.func.isRequired,
setDbError: PropTypes.func,
saveSearchQuery: PropTypes.func,
};
EnergiesPageInput.defaultProps = {
};
const mapStateToProps = (state) => ({
filter: state.get('energiesPageReducer').filter,
search: state.get('energiesPageReducer').search,
simpleSearch: state.get('energiesPageReducer').simpleSearch,
dbError: state.get('energiesPageReducer').dbError,
});
const mapDispatchToProps = (dispatch) => ({
receiveReactions: (reactions) => {
dispatch(actions.receiveReactions(reactions));
},
saveSearch: (search) => {
dispatch(actions.saveSearch(search));
},
saveResultSize: (resultSize) => {
dispatch(actions.saveResultSize(resultSize));
},
toggleSimpleSearch: () => {
dispatch(actions.toggleSimpleSearch());
},
setDbError: () => {
dispatch(actions.setDbError());
},
saveSearchQuery: (searchQuery) => {
dispatch(actions.saveSearchQuery(searchQuery));
},
});
export default withStyles(styles, { withTheme: true })(
connect(mapStateToProps, mapDispatchToProps)(EnergiesPageInput)
);
|
src/containers/AreaViewer.js
|
rodrigo-puente/poke-nostalgia
|
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { AreaViewer } from '../components/AreaViewer';
import ControlsContainer from './Controls';
import { setScreenFocus } from '../actions/Controls';
import { fetchPokedex } from '../actions/Pokedex';
import styles from '../styles/PokemonList';
import pokemonNames from '../data/PokemonNames';
class AreaViewerContainer extends Component {
componentWillMount() {
this.props.setScreenFocus("VIEWER");
}
getPokemonName = (pokemonId) => {
return pokemonNames[this.props.pokemonId - 1].toUpperCase();
}
render() {
return (
<div className="container" style={ styles.container }>
<div className="gbScreen" style={ styles.gbScreen }>
<AreaViewer pokemonName={ this.getPokemonName() }/>
</div>
<ControlsContainer/>
</div>
);
}
}
const mapStateToProps = (state, ownProps) => {
let { pokemonId } = ownProps.params;
return {
pokemonId: parseInt(pokemonId, 10)
}
}
const mapDispatchToProps = (dispatch) => {
return {
setScreenFocus: (screen) =>
dispatch(setScreenFocus(screen)),
fetchPokedex: (pokedexId) =>
dispatch(fetchPokedex(pokedexId))
}
}
export default connect(mapStateToProps, mapDispatchToProps)(AreaViewerContainer);
|
client/modules/Wizard/Steps/StepNumber1.js
|
zivkaziv/MazorTech
|
'use strict';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import MedicalDiagnosticItem from '../componenets/MedicalDiagnosticItem/MedicalDiagnosticItem';
import SearchInput, {createFilter} from 'react-search-input'
// Material
import FlatButton from 'material-ui/FlatButton';
import RaisedButton from 'material-ui/RaisedButton';
import Dialog from 'material-ui/Dialog';
import TextField from 'material-ui/TextField';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import lightTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
// Import Selectors
import { getMedicalRights } from '../WizardReducer';
// Styles
import searchInputStyles from './StepNumber1.css';
const styles = {
wizardStepPageStyle: {
maxHeight: 350,
// maxWidth: 679,
// overflow:'auto',
},
medicalDiagnosticsContainer:{
display:'flex'
},
searchContainer:{
height:383,
overflow:'auto'
},
cantFindContainer:{
textAlign:'center',
width:'100%'
},
dialogContentStyle:{
width: '50%',
maxWidth: 'none',
}
};
const KEYS_TO_FILTERS = ['condition'];
class StepNumber1 extends Component {
constructor(props) {
super(props);
this.state = {
searchTerm : '',
dialogOpen : false,
cantFindDialogOpen : false
};
this.searchUpdated = this.searchUpdated.bind(this);
this.handleOpen = this.handleOpen.bind(this);
this.handleClose = this.handleClose.bind(this);
this.handleCantFindDialogOpen = this.handleCantFindDialogOpen.bind(this);
this.handleCantFindDialogClose = this.handleCantFindDialogClose.bind(this);
this.isValidated = this.isValidated.bind(this);
}
isValidated() {
console.log('check is validate');
let isValid = false;
for(let index = 0; index < this.props.medicalRights.length; index++){
if(this.props.medicalRights[index].isSelected){
isValid = true;
break;
}
}
if(!isValid){
this.handleOpen();
}
return isValid;
}
searchUpdated (term) {
console.log(term);
this.setState({searchTerm: term})
}
componentDidMount() {
this.context.mixpanel.track('Wizard step open',{'ab_version':'v1','step':'1'});
}
handleOpen = () => {
this.setState({dialogOpen: true});
};
handleClose = () => {
this.setState({dialogOpen: false});
};
handleCantFindDialogOpen = () => {
this.context.mixpanel.track('Wizard step button',{'ab_version':'v1','step':'1','button':"can't find"});
this.setState({cantFindDialogOpen: true});
};
handleCantFindDialogClose = () => {
this.setState({cantFindDialogOpen: false});
};
getChildContext() {
return {
muiTheme: getMuiTheme(lightTheme),
};
}
render() {
const filteredMedicalDiagnostics = this.props.medicalRights.filter(createFilter(this.state.searchTerm, KEYS_TO_FILTERS));
const actions = [
<FlatButton
label="Ok"
primary={true}
keyboardFocused={true}
onTouchTap={this.handleClose}
/>,
];
const actionsCantFind = [
<FlatButton
label="OK"
primary={true}
keyboardFocused={true}
onTouchTap={this.handleCantFindDialogClose}
/>,
];
return (
<div className="step step1" style={styles.wizardStepPageStyle}>
<div className="row">
<div className="row" style={styles.searchContainer}>
<SearchInput placeholder='Search for your medical diagnostic'
className={searchInputStyles['search-input']}
onChange={this.searchUpdated} />
{filteredMedicalDiagnostics.map((medicalRight,i) => {
return (
<MedicalDiagnosticItem key={i} medicalRight={medicalRight}/>
)
})}
</div>
<div className="row" style={styles.cantFindContainer}>
<FlatButton
label="Can't find proper diagnostic"
primary={true}
fullWidth={true}
keyboardFocused={false}
contentStyle={styles.dialogContentStyle}
onTouchTap={this.handleCantFindDialogOpen}
/>
</div>
{/*Can't find dialog*/}
<Dialog
title="Can't find"
actions={actionsCantFind}
modal={true}
open={this.state.cantFindDialogOpen}
contentStyle={styles.dialogContentStyle}
onRequestClose={this.handleCantFindDialogClose}>
Sorry, but we aren't support it yet...
{/*<TextField hintText="Write here in your words the medical diagnostic"/>*/}
</Dialog>
{/*You must choose dialog*/}
<Dialog
title="Please choose"
actions={actions}
modal={true}
open={this.state.dialogOpen}
onRequestClose={this.handleClose}
>
You must select at least one medical diagnostic
</Dialog>
</div>
</div>
)
}
}
function mapStateToProps(state) {
return {
medicalRights: getMedicalRights(state)
};
}
StepNumber1.propTypes = {
medicalRight: PropTypes.any
};
StepNumber1.childContextTypes = {
muiTheme: React.PropTypes.object,
};
StepNumber1.contextTypes = {
router: React.PropTypes.object,
mixpanel: PropTypes.any
};
export default connect(mapStateToProps, null, null, { withRef: true })(StepNumber1);
|
src/components/app.js
|
samlawrencejones/react-starter
|
import React from 'react'
import Paper from 'material-ui/lib/paper'
import AppBar from 'material-ui/lib/app-bar'
import AddTodo from '../containers/AddTodo'
import VisibleTodoList from '../containers/VisibleTodoList'
import Footer from '../components/Footer'
export default class App extends React.Component {
render() {
return (
<div className="container">
<div className="body">
<AppBar
title="Todo List"
showMenuIconButton={false}
/>
<Paper style={{
width: '100%',
padding: 50,
textAlign: 'center'
}} zDepth={1}
rounded={false}>
<AddTodo />
<Footer />
<VisibleTodoList />
</Paper>
</div>
</div>
)
}
}
|
blueocean-material-icons/src/js/components/svg-icons/action/explore.js
|
jenkinsci/blueocean-plugin
|
import React from 'react';
import SvgIcon from '../../SvgIcon';
const ActionExplore = (props) => (
<SvgIcon {...props}>
<path d="M12 10.9c-.61 0-1.1.49-1.1 1.1s.49 1.1 1.1 1.1c.61 0 1.1-.49 1.1-1.1s-.49-1.1-1.1-1.1zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm2.19 12.19L6 18l3.81-8.19L18 6l-3.81 8.19z"/>
</SvgIcon>
);
ActionExplore.displayName = 'ActionExplore';
ActionExplore.muiName = 'SvgIcon';
export default ActionExplore;
|
index.android.js
|
jefflanzi/rn-app-template
|
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class appTemplate extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('appTemplate', () => appTemplate);
|
assets/jqwidgets/demos/react/app/formattedinput/exponentialnotation/app.js
|
juannelisalde/holter
|
import React from 'react';
import ReactDOM from 'react-dom';
import JqxFormattedInput from '../../../jqwidgets-react/react_jqxformattedinput.js';
import JqxButton from '../../../jqwidgets-react/react_jqxbuttons.js';
class App extends React.Component {
componentDidMount() {
this.refs.getDecimal.on('click', () => {
let decimalValue = this.refs.myFormattedInput.val('decimal');
alert('Decimal Value: ' + decimalValue);
});
this.refs.getExponential.on('click', () => {
let exponentialValue = this.refs.myFormattedInput.val('exponential');
alert('Exponential Notation: ' + exponentialValue);
});
this.refs.getScientific.on('click', () => {
let scientificValue = this.refs.myFormattedInput.val('scientific');
alert('Scientific Notation: ' + scientificValue);
});
this.refs.getEngineering.on('click', () => {
let engineeringValue = this.refs.myFormattedInput.val('engineering');
alert('Engineering Notation: ' + engineeringValue);
});
}
render() {
return (
<div>
<JqxFormattedInput ref='myFormattedInput'
width={200} height={25} radix={'decimal'}
value={330000} decimalNotation={'exponential'}
/>
<div style={{ marginTop: 20 }}>
<JqxButton ref='getDecimal' value='Get Decimal Value' style={{ float: 'left' }} width={175} />
<JqxButton ref='getExponential' value='Get Exponential Notation' style={{ marginLeft: 5, float: 'left' }} width={175} />
<br />
<br />
<JqxButton ref='getScientific' value='Get Scientific Notation' style={{ float: 'left' }} width={175} />
<JqxButton ref='getEngineering' value='Get Engineering Notation' style={{ marginLeft: 5, float: 'left' }} width={175} />
</div>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));
|
src/svg-icons/image/blur-circular.js
|
ichiohta/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let ImageBlurCircular = (props) => (
<SvgIcon {...props}>
<path d="M10 9c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1zm0 4c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1zM7 9.5c-.28 0-.5.22-.5.5s.22.5.5.5.5-.22.5-.5-.22-.5-.5-.5zm3 7c-.28 0-.5.22-.5.5s.22.5.5.5.5-.22.5-.5-.22-.5-.5-.5zm-3-3c-.28 0-.5.22-.5.5s.22.5.5.5.5-.22.5-.5-.22-.5-.5-.5zm3-6c.28 0 .5-.22.5-.5s-.22-.5-.5-.5-.5.22-.5.5.22.5.5.5zM14 9c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1zm0-1.5c.28 0 .5-.22.5-.5s-.22-.5-.5-.5-.5.22-.5.5.22.5.5.5zm3 6c-.28 0-.5.22-.5.5s.22.5.5.5.5-.22.5-.5-.22-.5-.5-.5zm0-4c-.28 0-.5.22-.5.5s.22.5.5.5.5-.22.5-.5-.22-.5-.5-.5zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm2-3.5c-.28 0-.5.22-.5.5s.22.5.5.5.5-.22.5-.5-.22-.5-.5-.5zm0-3.5c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1z"/>
</SvgIcon>
);
ImageBlurCircular = pure(ImageBlurCircular);
ImageBlurCircular.displayName = 'ImageBlurCircular';
ImageBlurCircular.muiName = 'SvgIcon';
export default ImageBlurCircular;
|
src/components/PastEvents.js
|
Outfitio/breakfast-series-landing
|
import React, { Component } from 'react';
import Link from 'gatsby-link';
export default class PastEvents extends Component {
render() {
const { events, currentPath } = this.props;
const sortedEvents = events.map(event => event.node.id).sort();
return(
<div>
{sortedEvents.map(id => (
<Link
key={id}
to={id}>
<span
style={{
...styles.calendarItem,
borderColor: id === currentPath ? 'white' : 'transparent'
}}
>
{id}
</span>
</Link>
))}
</div>
)
}
}
const styles = {
calendarItem: {
fontWeight: 'bold',
marginRight: '0.5em',
padding: '0.5em',
borderRadius: '3em',
border: '3px solid transparent'
}
}
|
src/Form.js
|
jsummer/react-ui
|
'use strict'
import React from 'react'
import classnames from 'classnames'
import { forEach } from './utils/objects'
import FormControl from './FormControl'
import FormSubmit from './FormSubmit'
import { requireCss } from './themes'
requireCss('form')
export default class Form extends React.Component {
static displayName = 'Form'
static propTypes = {
beforeSubmit: React.PropTypes.func,
children: React.PropTypes.any,
className: React.PropTypes.string,
data: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.func
]).isRequired,
hintType: React.PropTypes.oneOf(['block', 'none', 'pop', 'inline']),
layout: React.PropTypes.oneOf(['aligned', 'stacked', 'inline']),
onSubmit: React.PropTypes.func,
style: React.PropTypes.object
}
static defaultProps = {
data: {},
layout: 'inline'
}
componentWillMount () {
this.fetchData(this.props.data)
}
componentWillReceiveProps (nextProps) {
if (this.props.data !== this.props.data) {
this.fetchData(nextProps.data)
}
}
state = {
locked: false,
data: {}
}
fetchData (data) {
if (typeof data === 'function') {
data.then(res => {
this.fetchData(res)
})()
return
}
this.setState({ data })
this.setData(data)
}
getValue () {
let data = this.state.data
forEach(this.refs, (ref, k) => {
if (!ref.props.ignore) {
data[k] = ref.getValue()
}
})
return data
}
setValue (key, value) {
let data = this.state.data
data[key] = value
this.setState({ data })
}
setData (data) {
forEach(this.refs, (ref, k) => {
ref.setValue(data[k])
})
}
equalValidate (targetRef, equalRef) {
let self = this
return function () {
let target = self.refs[targetRef]
if (!target) {
console.warn(`equal target '${targetRef}' not existed`)
return false
}
let equal = self.refs[equalRef]
return target.getValue() === equal.getValue()
}
}
renderChildren () {
return React.Children.map(this.props.children, child => {
let props = {
hintType: child.props.hintType || this.props.hintType,
readOnly: child.props.readOnly || this.state.locked,
layout: this.props.layout
}
if (child.type === FormControl) {
if (!child.props.name) {
console.warn('FormControl must have a name!')
return null
}
props.ref = child.props.name
if (this.state.data[child.props.name] !== undefined) {
props.value = this.state.data[child.props.name]
}
if (child.props.equal) {
props.onValidate = this.equalValidate(child.props.equal, child.props.name)
}
} else if (child.type === FormSubmit) {
props.locked = this.state.locked
}
child = React.cloneElement(child, props)
return child
})
}
getReference (name) {
return this.refs[name]
}
validate () {
let success = true
forEach(this.refs, function (child) {
if (child.props.ignore) {
return
}
let suc = child.validate()
success = success && suc
})
return success
}
handleSubmit (event) {
if (this.state.locked) {
return
}
event.preventDefault()
this.onSubmit()
}
onSubmit () {
this.setState({ locked: true })
let success = this.validate()
if (success && this.props.beforeSubmit) {
success = this.props.beforeSubmit()
}
if (!success) {
this.setState({ locked: false })
return
}
if (this.props.onSubmit) {
this.props.onSubmit(this.getValue())
this.setState({ locked: false })
}
}
render () {
let className = classnames(
this.props.className,
'rct-form',
{
'rct-form-aligned': this.props.layout === 'aligned',
'rct-form-inline': this.props.layout === 'inline',
'rct-form-stacked': this.props.layout === 'stacked'
}
)
return (
<form onSubmit={this.handleSubmit.bind(this)} style={this.props.style} className={className}>
{this.renderChildren()}
</form>
)
}
}
|
src/components/Divider.js
|
henrytao-me/react-native-mdcore
|
import React from 'react'
import { View } from 'react-native'
import PropTypes from './PropTypes'
import PureComponent from './PureComponent'
import StyleSheet from './StyleSheet'
export default class Divider extends PureComponent {
static contextTypes = {
theme: PropTypes.any
}
static propTypes = {
largePadding: PropTypes.bool
}
render() {
const { theme } = this.context
const styles = Styles.get(theme, this.props)
return (
<View style={[styles.container, this.props.style]} />
)
}
}
const Styles = StyleSheet.create((theme, opts = {}) => {
let { largePadding } = opts
const container = {
backgroundColor: theme.divider.color,
height: theme.divider.size,
marginLeft: largePadding ? (2 * theme.list.paddingLeft + theme.list.avatarSize) : 0
}
return { container }
})
|
app/src/components/content/Problems/ProblemDetail/problemdes/index.js
|
ouxu/NEUQ-OJ
|
/**
* Created by out_xu on 17/1/8.
*/
import React from 'react'
import { Card, Collapse } from 'antd'
import './index.less'
import Markdown from 'components/plugins/Markdown'
const Panel = Collapse.Panel
const createMarkup = html => ({__html: html})
const return2Br = (str) => {
str = str || ''
return str.replace(/\r?\n/g, '<br/>')
}
const customPanelStyle = {}
const ProblemDes = ({data = {}}) => (
<Collapse
defaultActiveKey={['problem-des', 'problem-sampleinput', 'problem-sampleoutput']}
bordered={false}
className='problem-detail-main'
>
<Panel header='描述' key='problem-des' style={customPanelStyle}>
<Card bodyStyle={{fontSize: 14}} className='problem-detail-main-desc'>
<h4>题目描述:</h4>
<Markdown content={data.description} />
<h4>输入:</h4>
<Markdown content={data.input} />
<h4>输出:</h4>
<Markdown content={data.output} />
</Card>
</Panel>
<Panel header='样例输入' key='problem-sampleinput'>
<Card >
<pre dangerouslySetInnerHTML={createMarkup(return2Br(data.sample_input))} />
</Card>
</Panel>
<Panel header='样例输出' key='problem-sampleoutput'>
<Card>
<pre dangerouslySetInnerHTML={createMarkup(return2Br(data.sample_output))} />
</Card>
</Panel>
{
data.hint &&
<Panel header='提示' key='problem-hint'>
<Card>
<Markdown content={data.hint} />
</Card>
</Panel>
}
</Collapse>
)
export default ProblemDes
|
src/Well.js
|
nickuraltsev/react-bootstrap
|
import React from 'react';
import classNames from 'classnames';
import BootstrapMixin from './BootstrapMixin';
const Well = React.createClass({
mixins: [BootstrapMixin],
getDefaultProps() {
return {
bsClass: 'well'
};
},
render() {
let classes = this.getBsClassSet();
return (
<div {...this.props} className={classNames(this.props.className, classes)}>
{this.props.children}
</div>
);
}
});
export default Well;
|
app/javascript/mastodon/features/account/components/account_note.js
|
imas/mastodon
|
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import Textarea from 'react-textarea-autosize';
import { is } from 'immutable';
const messages = defineMessages({
placeholder: { id: 'account_note.placeholder', defaultMessage: 'Click to add a note' },
});
class InlineAlert extends React.PureComponent {
static propTypes = {
show: PropTypes.bool,
};
state = {
mountMessage: false,
};
static TRANSITION_DELAY = 200;
componentWillReceiveProps (nextProps) {
if (!this.props.show && nextProps.show) {
this.setState({ mountMessage: true });
} else if (this.props.show && !nextProps.show) {
setTimeout(() => this.setState({ mountMessage: false }), InlineAlert.TRANSITION_DELAY);
}
}
render () {
const { show } = this.props;
const { mountMessage } = this.state;
return (
<span aria-live='polite' role='status' className='inline-alert' style={{ opacity: show ? 1 : 0 }}>
{mountMessage && <FormattedMessage id='generic.saved' defaultMessage='Saved' />}
</span>
);
}
}
export default @injectIntl
class AccountNote extends ImmutablePureComponent {
static propTypes = {
account: ImmutablePropTypes.map.isRequired,
value: PropTypes.string,
onSave: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
state = {
value: null,
saving: false,
saved: false,
};
componentWillMount () {
this._reset();
}
componentWillReceiveProps (nextProps) {
const accountWillChange = !is(this.props.account, nextProps.account);
const newState = {};
if (accountWillChange && this._isDirty()) {
this._save(false);
}
if (accountWillChange || nextProps.value === this.state.value) {
newState.saving = false;
}
if (this.props.value !== nextProps.value) {
newState.value = nextProps.value;
}
this.setState(newState);
}
componentWillUnmount () {
if (this._isDirty()) {
this._save(false);
}
}
setTextareaRef = c => {
this.textarea = c;
}
handleChange = e => {
this.setState({ value: e.target.value, saving: false });
};
handleKeyDown = e => {
if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) {
e.preventDefault();
this._save();
if (this.textarea) {
this.textarea.blur();
}
} else if (e.keyCode === 27) {
e.preventDefault();
this._reset(() => {
if (this.textarea) {
this.textarea.blur();
}
});
}
}
handleBlur = () => {
if (this._isDirty()) {
this._save();
}
}
_save (showMessage = true) {
this.setState({ saving: true }, () => this.props.onSave(this.state.value));
if (showMessage) {
this.setState({ saved: true }, () => setTimeout(() => this.setState({ saved: false }), 2000));
}
}
_reset (callback) {
this.setState({ value: this.props.value }, callback);
}
_isDirty () {
return !this.state.saving && this.props.value !== null && this.state.value !== null && this.state.value !== this.props.value;
}
render () {
const { account, intl } = this.props;
const { value, saved } = this.state;
if (!account) {
return null;
}
return (
<div className='account__header__account-note'>
<label htmlFor={`account-note-${account.get('id')}`}>
<FormattedMessage id='account.account_note_header' defaultMessage='Note' /> <InlineAlert show={saved} />
</label>
<Textarea
id={`account-note-${account.get('id')}`}
className='account__header__account-note__content'
disabled={this.props.value === null || value === null}
placeholder={intl.formatMessage(messages.placeholder)}
value={value || ''}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
onBlur={this.handleBlur}
ref={this.setTextareaRef}
/>
</div>
);
}
}
|
pkg/interface/dbug/src/index.js
|
urbit/urbit
|
import React from 'react';
import ReactDOM from 'react-dom';
import { Root } from '/components/root';
import { api } from '/api';
import { store } from '/store';
import { subscription } from "/subscription";
api.setAuthTokens({
ship: window.ship
});
window.urb = new window.channel();
subscription.start();
ReactDOM.render((
<Root />
), document.querySelectorAll("#root")[0]);
|
src/svg-icons/action/note-add.js
|
tan-jerene/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let ActionNoteAdd = (props) => (
<SvgIcon {...props}>
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 14h-3v3h-2v-3H8v-2h3v-3h2v3h3v2zm-3-7V3.5L18.5 9H13z"/>
</SvgIcon>
);
ActionNoteAdd = pure(ActionNoteAdd);
ActionNoteAdd.displayName = 'ActionNoteAdd';
ActionNoteAdd.muiName = 'SvgIcon';
export default ActionNoteAdd;
|
imports/ui/components/AuthenticatedNavigation/Menu.js
|
haraneesh/mydev
|
// import React, { Component } from 'react';
import React, { useState, useEffect } from 'react';
import { Button, Row } from 'react-bootstrap';
import PropTypes from 'prop-types';
/* export default class Menu extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
};
this.show = this.show.bind(this);
this.hide = this.hide.bind(this);
} */
const Menu = (props) => {
const [isMenuVisible, setMenuVisibility] = useState(false);
useEffect(() => {
setMenuVisibility(false);
}, []);
const hide = () => {
setMenuVisibility(false);
document.removeEventListener('click', hide);
};
const show = () => {
if (!isMenuVisible) {
document.addEventListener('click', hide);
}
setMenuVisibility(true);
};
const menuVisible = isMenuVisible ? 'visible' : ''; // this.state.visible ? 'visible ' : '';
return (
<Row className="pull-right">
<span
id="profileIcon"
style={{
marginTop: '2.4rem', marginRight: '15px', float: 'left', fontSize: '1.25em', display: 'block',
}}
>
<a onClick={() => { props.history.push('/profile'); }} href="#">
<i className="fas fa-user" style={{ color: '#522E23' }} />
</a>
</span>
<div className="menu-expand-button">
<Button type="button" bsStyle="link" onClick={show}>
<span className={`icon-bar top-bar ${menuVisible}`} />
<span className={`icon-bar middle-bar ${menuVisible}`} />
<span className={`icon-bar bottom-bar ${menuVisible}`} />
</Button>
</div>
<div className="menu" style={{ display: (isMenuVisible) ? 'block' : 'none' }}>
<div className={menuVisible + props.alignment} style={{ zIndex: 1100 }}>
{props.children}
</div>
</div>
</Row>
);
};
export default Menu;
Menu.propTypes = {
alignment: PropTypes.string.isRequired,
children: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
|
WasteAppMini/js/components/recipe/cheese.js
|
airien/workbits
|
import React, { Component } from 'react';
import { Image,View, ListView,BackAndroid } from 'react-native';
import { connect } from 'react-redux';
import { actions } from 'react-native-navigation-redux-helpers';
import { Container, Header, Title, Content, Button, Icon, Card, CardItem, Text, Thumbnail, DeckSwiper } from 'native-base';
var menuItems = require('../../data/sidebar.json');
import myTheme from '../../themes/base-theme';
import { openDrawer } from '../../actions/drawer';
var recipes = require('../../data/ost.json');
var recipeItems = require('../../data/menurecipes.json');
import styles from './styles';
import Hyperlink from 'react-native-hyperlink'
import Images from '../../../assets/images';
import DynamicView from '../dynamicview/';
import AndroidBackButton from "react-native-android-back-button"
const {
replaceAt,
} = actions;
class Cheese extends Component {
constructor(props) {
super(props);
this.state = {
recipe: 0
};
}
static propTypes = {
openDrawer: React.PropTypes.func,
replaceAt: React.PropTypes.func,
navigation: React.PropTypes.shape({
key: React.PropTypes.string,
}),
}
replaceAt(route) {
this.props.replaceAt('cheese', { key: route }, this.props.navigation.key);
}
render() {
return (
<Container theme={myTheme} style={styles.container}>
<AndroidBackButton
onPress={() => {this.replaceAt("recipe"); }}
/>
<Header>
<Title>{recipeItems.cheese}</Title>
<Button transparent onPress={this.props.openDrawer}>
<Icon name="ios-menu" />
</Button>
</Header>
<Content padder>
<DynamicView data={recipes.texts} name="cheese" />
</Content>
</Container>
);
}
}
function bindAction(dispatch) {
return {
openDrawer: () => dispatch(openDrawer()),
replaceAt: (routeKey, route, key) => dispatch(replaceAt(routeKey, route, key)),
};
}
const mapStateToProps = state => ({
navigation: state.cardNavigation,
});
export default connect(mapStateToProps, bindAction)(Cheese);
|
src/components/EditGearForm.js
|
tommydx/front2
|
import React, { Component } from 'react';
import axios from 'axios';
import { browserHistory } from 'react-router';
class EditGearForm extends Component {
constructor(props) {
super(props);
this.state = {
name: "",
item_category: "",
item: "",
manufacturer: "",
year: "",
serial_number: "",
condition: "",
description: "",
photo_1: "",
photo_2: "",
photo_3: "",
user_id: 0
};
this.handleChange = this.handleChange.bind(this);
}
componentDidMount() {
console.log('=========>',this.state)
axios
.get(`http://localhost:8080/users/${window.localStorage.user_id}/gear/${this.props.gear_id}`, {
headers: {
'Authorization': window.localStorage.getItem('token')
}
})
.then((response) => {
const gearData = response.data;
console.log('======>2',gearData)
this.setState({
gearData});
})
.catch((err) => {
console.log(err);
});
}
handleSubmit(event) {
event.preventDefault();
axios
.put(`http://localhost:8080/users/${window.localStorage.user_id}/gear/${this.props.gear_id}`, {
gear: this.state
}, {
headers: {
'Authorization': window.localStorage.getItem('token')
}
})
.then(() => {
browserHistory.push(`/gear/${this.props.userId}/gear/${this.props.gearId}`);
})
.catch((err) => {
console.log(err);
});
}
// VALUE MUST BE EQUAL TO THE STATE OF THE COMPONENT YOU ARE IN WHEN TAKING DATA FROM INPUT FIELDS (HOISTED STATE) ---- CAN NOT DO THIS WITH PROPS - USE PLACEHOLDER
handleChange(event) {
this.setState({
[event.target.name]: event.target.value
});
}
render() {
return(
<div className='edit-gear-form-contain'>
<div className='edit-gear-form-inputs'>
<form onSubmit={this.handleSubmit.bind(this)}>
<div>
<div className='formLabel'>
Name
</div>
<span>
<input onChange={this.handleChange} name='name' type='text' placeholder={this.props.gearData.name}/>
</span>
</div>
<div>
<div className='formLabel'>
Item Category
</div>
<span>
<input onChange={this.handleChange} name='item_category' type='text' placeholder={this.props.gearData.item_category}/>
</span>
</div>
<div>
<div className='formLabel'>
Item
</div>
<span>
<input onChange={this.handleChange} name='item' type='text' placeholder={this.props.gearData.item}/>
</span>
</div>
<div>
<div className='formLabel'>
Manufacturer
</div>
<span>
<input onChange={this.handleChange} name='manufacturer' type='text' placeholder={this.props.gearData.manufacturer}/>
</span>
</div>
<div>
<div className='formLabel'>
Year
</div>
<span>
<input onChange={this.handleChange} name='year' type='text' placeholder={this.props.gearData.year}/>
</span>
</div>
<div>
<div className='formLabel'>
Serial Number
</div>
<span>
<input onChange={this.handleChange} name='serial_number' type='text' placeholder={this.props.gearData.serial_number}/>
</span>
</div>
<div>
<div className='formLabel'>
Condition
</div>
<span>
<input onChange={this.handleChange} name='condition' type='text' placeholder={this.props.gearData.condition}/>
</span>
</div>
<div>
<div className='formLabel'>
Description
</div>
<span>
<input onChange={this.handleChange} name='description' type='text' placeholder={this.props.gearData.description}/>
</span>
</div>
<div>
<div className='formLabel'>
Add Photo
</div>
<span>
<input onChange={this.handleChange} name='photo_1' type='text' placeholder={this.props.gearData.photo_1}/>
</span>
</div>
<div>
<div className='formLabel'>
Add Photo
</div>
<span>
<input onChange={this.handleChange} name='photo_2' type='text' placeholder={this.props.gearData.photo_2}/>
</span>
</div>
<div>
<div className='formLabel'>
Add Photo
</div>
<span>
<input onChange={this.handleChange} name='photo_3' type='text' placeholder={this.props.gearData.photo_3}/>
</span>
</div>
<div className='hidden-ui'>
<input onChange={this.handleChange} name='user_id' type='text' placeholder={this.props.gearData.user_id} />
</div>
<div className=''>
<button type='submit' className='edit-gear-button button'>Update Item</button>
</div>
</form>
</div>
<div className='gear-photos'>
<img src={`${this.state.photo_1}`} width='100%'/>
<img src={`${this.state.photo_2}`} width='100%'/>
<img src={`${this.state.photo_3}`} width='100%'/>
</div>
</div>
);
}
}
export default EditGearForm;
|
src/index.js
|
dkryaklin/aviasales_test
|
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import './css/index.css';
import './css/media.css';
ReactDOM.render(
<App />,
document.getElementById('root')
);
|
src/Portal.js
|
cesarandreu/react-overlays
|
import React from 'react';
import mountable from 'react-prop-types/lib/mountable';
import ownerDocument from './utils/ownerDocument';
import getContainer from './utils/getContainer';
/**
* The `<Portal/>` component renders its children into a new "subtree" outside of current component hierarchy.
* You can think of it as a declarative `appendChild()`, or jQuery's `$.fn.appendTo()`.
* The children of `<Portal/>` component will be appended to the `container` specified.
*/
let Portal = React.createClass({
displayName: 'Portal',
propTypes: {
/**
* A Node, Component instance, or function that returns either. The `container` will have the Portal children
* appended to it.
*/
container: React.PropTypes.oneOfType([
mountable,
React.PropTypes.func
])
},
componentDidMount() {
this._renderOverlay();
},
componentDidUpdate() {
this._renderOverlay();
},
componentWillUnmount() {
this._unrenderOverlay();
this._unmountOverlayTarget();
},
_mountOverlayTarget() {
if (!this._overlayTarget) {
this._overlayTarget = document.createElement('div');
this.getContainerDOMNode()
.appendChild(this._overlayTarget);
}
},
_unmountOverlayTarget() {
if (this._overlayTarget) {
this.getContainerDOMNode()
.removeChild(this._overlayTarget);
this._overlayTarget = null;
}
},
_renderOverlay() {
let overlay = !this.props.children
? null
: React.Children.only(this.props.children);
// Save reference for future access.
if (overlay !== null) {
this._mountOverlayTarget();
this._overlayInstance = React.render(overlay, this._overlayTarget);
} else {
// Unrender if the component is null for transitions to null
this._unrenderOverlay();
this._unmountOverlayTarget();
}
},
_unrenderOverlay() {
if (this._overlayTarget) {
React.unmountComponentAtNode(this._overlayTarget);
this._overlayInstance = null;
}
},
render() {
return null;
},
getMountNode(){
return this._overlayTarget;
},
getOverlayDOMNode() {
if (!this.isMounted()) {
throw new Error('getOverlayDOMNode(): A component must be mounted to have a DOM node.');
}
if (this._overlayInstance) {
if (this._overlayInstance.getWrappedDOMNode) {
return this._overlayInstance.getWrappedDOMNode();
} else {
return React.findDOMNode(this._overlayInstance);
}
}
return null;
},
getContainerDOMNode() {
return getContainer(this.props.container, ownerDocument(this).body);
}
});
export default Portal;
|
app/components/ShowJob/index.js
|
dijahmac/JobWeasel-FrontEnd
|
/**
*
* ShowJob
*
*/
import React from 'react';
import './style.css';
import './styleM.css';
export default class ShowJob extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
job: {},
links: []
}
}
componentWillMount() {
this.getJob(this.props.jobId);
this.getLinks(this.props.jobId);
}
getJob = (id) => {
let url = "http://localhost:8000/api/showJob/" + id;
let _this = this;
fetch(url, {method: 'GET'}).then(
function(response) {
return response.json();
}
).then(
function(json) {
_this.setState({
job: json.job
});
console.log("showJob");
console.log(json.job);
}.bind(this)
);
}
getLinks = (id) => {
let url = "http://localhost:8000/api/getJobLinks/" + id;
let _this = this;
fetch(url, {method: 'GET'}).then(
function(response) {
return response.json();
}
).then(
function(json) {
_this.setState({
links: json.links
});
console.log(url);
console.log(json.links);
}.bind(this)
);
}
renderJob = (job) => {
return (
<div className="jobSection">
{this.renderField("Name", job.name)}
{this.renderField("Location", job.location)}
{this.renderField("Description", job.description)}
{this.renderField("Budget", job.budget)}
{this.renderField("Workers Needed", job.workers_needed)}
{this.renderField("Start Date", job.start_date)}
{this.renderField("Time Frame", job.time_frame)}
{this.renderField("Posted on", job.created_at)}
</div>
);
}
renderField = (name, value) => {
return (
<div className="jobField panel">
<div className="jobField label">{name}:</div>
<div className="jobField value">
{value}
</div>
</div>
);
}
renderLinks = () => {
return (
<div className="linksSection">
<div className="links panel">
<div className="links label">Links:</div>
<div className="links value">
{this.state.links.map((link, index) => (
<div className="userLink" key={index}>
<a href={link.url}>{link.text}</a>
</div>
))}
</div>
</div>
</div>
);
}
render() {
let job = "";
let links = "";
if (this.state.job !== {}) {
job = this.renderJob(this.state.job);
}
if (this.state.links !== []) {
links = this.renderLinks();
}
return (
<div className="job">
{job}
{links}
</div>
);
}
}
ShowJob.contextTypes = {
router: React.PropTypes.object
};
|
app/config/routes.js
|
khaiphan/react-server-boilerplate
|
import React from 'react';
import { Router, Route, IndexRoute } from 'react-router';
import App from '../components/App';
import Main from '../components/Main';
import Home from '../components/Home';
import User from '../components/User';
export default(
<Router>
<Route component={Main}>
<Route path='/' component={Home} />
<Route path='/user' component={User} />
</Route>
</Router>
);
|
packages/react/src/components/organisms/TabContainer/context.js
|
massgov/mayflower
|
import React from 'react';
// Used by @Organisms/TabContainer and Tab to share data.
const TabContext = React.createContext({
activeTab: null,
activeContent: null,
setActiveTab: () => {}
});
export default TabContext;
|
pages/designs/signinform/components/form.js
|
DarcyChan/darcychan.com
|
import React from 'react';
import { Motion, spring } from 'react-motion';
export default class Form extends React.Component {
render() {
const {
formRef,
activeRef,
info,
isActive,
isSubmitted,
motion,
reverse,
onSwitch,
onSubmit,
onFormRest,
children,
...props
} = this.props;
const dir = reverse ? 1 : -1;
return (
<Motion
style={{
opacity: spring(isActive && !isSubmitted ? 1 : 0, motion),
position: spring(isActive ? 0 : dir * 100, motion)
}}
onRest={() => onFormRest()}
>
{({ opacity, position }) => (
<div
className={`form-container${isActive
? ' active'
: ''}${reverse ? ' reverse' : ''}${isSubmitted
? ' submitted'
: ''}`}
{...props}
style={{
left: `${position}%`,
opacity: opacity,
visibility: opacity > 0 ? 'visible' : 'hidden',
transform:
opacity < 1 && opacity > 0
? 'translateZ(0)'
: 'none'
}}
ref={formRef}
>
<Motion
style={{
position: spring(
isSubmitted ? dir * 100 : 0,
motion
)
}}
>
{({ position }) => (
<div
className="form-content form-content-active"
style={{
left: `${position}%`
}}
ref={activeRef}
>
{info &&
info.activeTitle && (
<h1 className="form-title">
{info.activeTitle}
</h1>
)}
{info &&
info.activeDesc && <p>{info.activeDesc}</p>}
<form onSubmit={onSubmit}>{children}</form>
</div>
)}
</Motion>
<Motion
style={{
position: spring(
isSubmitted ? dir * -100 : 0,
motion
)
}}
>
{({ position }) => (
<div
className="form-content form-content-default"
style={{
left: `${position}%`
}}
>
{info &&
info.defaultTitle && (
<h1 className="form-title">
{info.defaultTitle}
</h1>
)}
{info &&
info.defaultDesc && (
<p>{info.defaultDesc}</p>
)}
{info &&
info.toggleText && (
<button
type="button"
onClick={onSwitch}
>
{info.toggleText}
</button>
)}
</div>
)}
</Motion>
</div>
)}
</Motion>
);
}
}
|
src/components/common/svg-icons/editor/format-align-center.js
|
abzfarah/Pearson.NAPLAN.GnomeH
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let EditorFormatAlignCenter = (props) => (
<SvgIcon {...props}>
<path d="M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z"/>
</SvgIcon>
);
EditorFormatAlignCenter = pure(EditorFormatAlignCenter);
EditorFormatAlignCenter.displayName = 'EditorFormatAlignCenter';
EditorFormatAlignCenter.muiName = 'SvgIcon';
export default EditorFormatAlignCenter;
|
docs/src/pages/elements/NavigationPage.js
|
gocreating/react-tocas
|
import React from 'react';
import DemoPageLayout from '../../utils/DemoPageLayout';
import CardList from '../../utils/CardList';
let NavigationPage = () => (
<DemoPageLayout
title="Elements"
description="Uncategorized elements"
>
<CardList
title="Elements"
cards={[{
to: '/elements/button',
title: 'Button',
meta: '<Button />, <Buttons />',
description: 'Clickable and feedback related component',
symbol: <i className="icon hand pointer" />,
}, {
to: '/elements/container',
title: 'Container',
meta: '<Container />',
description: 'Centralize text content especially in high display resolution',
symbol: <i className="icon resize horizontal" />,
}, {
to: '/elements/header',
title: 'Header',
meta: '<Header />',
description: 'To separate text content',
symbol: <i className="icon header" />,
}, {
to: '/elements/icon',
title: 'Icon',
meta: '<Icon />, <Icons />',
description: '',
symbol: <i className="icon smile" />,
}, {
to: '/elements/image',
title: 'Image',
meta: '<Image />, <Images />',
description: '',
symbol: <i className="icon picture" />,
}, {
to: '/elements/slate',
title: 'Slate',
meta: '<Slate />',
description: 'Multi-functional block like header container, placeholder or uploading area',
symbol: <i className="icon square" />,
}, {
to: '/elements/segment',
title: 'Segment',
meta: '<Segment />, <Segments />',
description: 'To wrap text',
symbol: <i className="icon content" />,
}]}
/>
</DemoPageLayout>
);
export default NavigationPage;
|
src/components/TodoApp/Header.js
|
Capgemini/react-scaffold
|
import React, { Component } from 'react';
import TodoActions from '../../actions/TodoActions';
import TodoTextInput from './TodoTextInput';
export default class Header extends Component {
/**
* Event handler called within TodoTextInput.
* Defining this here allows TodoTextInput to be used in multiple places
* in different ways.
* @param {string} text
*/
onSave(text) {
if (text.trim()){
TodoActions.create(text);
}
}
render() {
return (
<header id="header">
<h2>Todo app</h2>
<TodoTextInput
id="new-todo"
placeholder="What needs to be done?"
onSave={this.onSave}
/>
</header>
);
}
}
|
src/svg-icons/maps/local-shipping.js
|
kittyjumbalaya/material-components-web
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let MapsLocalShipping = (props) => (
<SvgIcon {...props}>
<path d="M20 8h-3V4H3c-1.1 0-2 .9-2 2v11h2c0 1.66 1.34 3 3 3s3-1.34 3-3h6c0 1.66 1.34 3 3 3s3-1.34 3-3h2v-5l-3-4zM6 18.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm13.5-9l1.96 2.5H17V9.5h2.5zm-1.5 9c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"/>
</SvgIcon>
);
MapsLocalShipping = pure(MapsLocalShipping);
MapsLocalShipping.displayName = 'MapsLocalShipping';
MapsLocalShipping.muiName = 'SvgIcon';
export default MapsLocalShipping;
|
features/apimgt/org.wso2.carbon.apimgt.publisher.feature/src/main/resources/publisher/source/src/app/components/Apis/Details/Resources/Resources.js
|
abimarank/carbon-apimgt
|
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react'
import { Input, Icon, Checkbox, Button, Card, Tag, Form } from 'antd';
import { Row, Col } from 'antd';
import Api from '../../../../data/api'
import Resource from './Resource'
const CheckboxGroup = Checkbox.Group;
class Resources extends React.Component{
constructor(props){
super(props);
this.state ={
tmpMethods:[],
tmpResourceName: '',
paths:{},
swagger:{}
};
this.api = new Api();
this.api_uuid = props.match.params.api_uuid;
this.addResources = this.addResources.bind(this);
this.onChange = this.onChange.bind(this);
this.onChangeInput = this.onChangeInput.bind(this);
this.updatePath = this.updatePath.bind(this);
this.updateResources = this.updateResources.bind(this);
}
componentDidMount() {
let promised_api = this.api.getSwagger(this.api_uuid);
promised_api.then((response) => {
this.setState({swagger:response.obj});
if(response.obj.paths !== undefined ){
this.setState({paths:response.obj.paths})
}
}).catch(error => {
if (process.env.NODE_ENV !== "production")
console.log(error);
let status = error.status;
if (status === 404) {
this.setState({notFound: true});
} else if (status === 401) {
this.setState({isAuthorize: false});
let params = qs.stringify({reference: this.props.location.pathname});
this.props.history.push({pathname: "/login", search: params});
}
});
}
onChange(checkedValues) {
console.log('checked = ', checkedValues);
this.setState({tmpMethods:checkedValues});
}
onChangeInput(e) {
console.log('checked = ', e.target.value);
this.setState({tmpResourceName:e.target.value});
}
addResources(){
const defaultGet = {
description:'description',
produces:'application/xml,application/json',
consumes:'application/xml,application/json',
parameters:[],
responses: {
200: {
"description": ""
}
}
};
const defaultPost = {
description: 'description',
produces: 'application/xml,application/json',
consumes: 'application/xml,application/json',
responses: {
200: {
"description": ""
}
},
parameters: [
{
name: "Payload",
description: "Request Body",
required: false,
in: "body",
schema: {
type: "object",
properties: {
payload: {
type: "string"
}
}
}
}
]
};
let pathValue = {};
this.state.tmpMethods.map( (method ) => {
switch (method) {
case "GET" :
pathValue["GET"] = defaultGet;
break;
case "POST" :
pathValue["POST"] = defaultPost;
}
});
let tmpPaths = this.state.paths;
tmpPaths[this.state.tmpResourceName] = pathValue;
this.setState({paths:tmpPaths});
}
updatePath(path,method,value) {
let tmpPaths = this.state.paths;
tmpPaths[path][method] = value;
this.setState({paths:tmpPaths});
}
updateResources(){
let tmpSwagger = this.state.swagger;
tmpSwagger.paths = this.state.paths;
this.setState({api:tmpSwagger});
let promised_api = this.api.updateSwagger(this.api_uuid, this.state.swagger);
promised_api.then((response) => {
}).catch(error => {
if (process.env.NODE_ENV !== "production")
console.log(error);
let status = error.status;
if (status === 404) {
this.setState({notFound: true});
} else if (status === 401) {
this.setState({isAuthorize: false});
let params = qs.stringify({reference: this.props.location.pathname});
this.props.history.push({pathname: "/login", search: params});
}
});
}
render(){
const selectBefore = (
<span>/SwaggerPetstore/1.0.0</span>
);
const plainOptions = ['GET','POST','PUT','DELETE','PATCH','HEAD','OPTIONS'];
let paths = this.state.paths;
return (
<div>
<h2>Resources</h2>
<Card title="Add Resource For Path" style={{ width: "100%",marginBottom:20 }}>
<Row type="flex" justify="start">
<Col span={4}>URL Pattern</Col>
<Col span={20}>
<Input addonBefore={selectBefore} onChange={this.onChangeInput} defaultValue="" />
<div style={{marginTop:20}}>
<CheckboxGroup options={plainOptions} onChange={this.onChange} />
</div>
<div style={{marginTop:20}}>
<Button type="primary" onClick={this.addResources}>Add Resources to Path</Button>
</div>
</Col>
</Row>
</Card>
{
Object.keys(paths).map(
(key) => {
let path = paths[key];
let that = this;
return (
Object.keys(path).map( (innerKey) => {
return <Resource path={key} method={innerKey} methodData={path[innerKey]} updatePath={that.updatePath} />
})
);
}
)
}
<input type="button" onClick={this.updateResources} value="Save"/>
</div>
)
}
}
export default Resources
|
src/svg-icons/device/battery-charging-60.js
|
matthewoates/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let DeviceBatteryCharging60 = (props) => (
<SvgIcon {...props}>
<path fillOpacity=".3" d="M15.67 4H14V2h-4v2H8.33C7.6 4 7 4.6 7 5.33V11h3.87L13 7v4h4V5.33C17 4.6 16.4 4 15.67 4z"/><path d="M13 12.5h2L11 20v-5.5H9l1.87-3.5H7v9.67C7 21.4 7.6 22 8.33 22h7.33c.74 0 1.34-.6 1.34-1.33V11h-4v1.5z"/>
</SvgIcon>
);
DeviceBatteryCharging60 = pure(DeviceBatteryCharging60);
DeviceBatteryCharging60.displayName = 'DeviceBatteryCharging60';
DeviceBatteryCharging60.muiName = 'SvgIcon';
export default DeviceBatteryCharging60;
|
indico/web/client/js/jquery/widgets/jinja/duration_widget.js
|
ThiefMaster/indico
|
// This file is part of Indico.
// Copyright (C) 2002 - 2021 CERN
//
// Indico is free software; you can redistribute it and/or
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.
import React from 'react';
import ReactDOM from 'react-dom';
import {WTFDurationField} from 'indico/react/components';
window.setupDurationWidget = function setupDurationWidget({fieldId, required, disabled}) {
// Make sure the results dropdown is displayed above the dialog.
const field = $(`#${fieldId}`);
field.closest('.ui-dialog-content').css('overflow', 'inherit');
field.closest('.exclusivePopup').css('overflow', 'inherit');
ReactDOM.render(
<WTFDurationField
timeId={`${fieldId}-timestorage`}
required={required}
disabled={disabled}
/>,
document.getElementById(fieldId)
);
};
|
lib/ui/src/components/preview/preview.stories.js
|
storybooks/react-storybook
|
import React from 'react';
import { storiesOf } from '@storybook/react';
import { types } from '@storybook/addons';
import { Preview } from './preview';
export const previewProps = {
id: 'string',
api: {
on: () => {},
emit: () => {},
off: () => {},
},
storyId: 'string',
path: 'string',
viewMode: 'story',
location: {},
baseUrl: 'http://example.com',
queryParams: {},
getElements: type =>
type === types.TAB
? [
{
id: 'notes',
type: types.TAB,
title: 'Notes',
route: ({ storyId }) => `/info/${storyId}`, // todo add type
match: ({ viewMode }) => viewMode === 'info', // todo add type
render: () => null,
},
]
: [],
options: {
isFullscreen: false,
isToolshown: true,
},
actions: {},
};
storiesOf('UI/Preview/Preview', module)
.addParameters({
component: Preview,
})
.add('no tabs', () => <Preview {...previewProps} getElements={() => []} />)
.add('with tabs', () => <Preview {...previewProps} />);
|
assets/jqwidgets/demos/react/app/complexinput/validation/app.js
|
juannelisalde/holter
|
import React from 'react';
import ReactDOM from 'react-dom';
import JqxComplexInput from '../../../jqwidgets-react/react_jqxcomplexinput.js';
import JqxButton from '../../../jqwidgets-react/react_jqxbuttons.js';
class App extends React.Component {
componentDidMount() {
this.refs.myButton.on('click', () => {
this.refs.myComplexInput.value('11- 2ii');
});
}
render() {
return (
<div>
<JqxComplexInput ref='myComplexInput'
width={250} height={25} value={'15 + 7.2i'} spinButtons={false}
/>
<JqxButton style={{ marginTop: 20 }} ref='myButton' width={200}
value='Set wrong value: "11- 2ii"'
/>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));
|
src/TabBar.js
|
LHoin/react-native-router-redux-plus
|
import React, { Component } from 'react';
import Tabs from 'react-native-tabs';
import { Image, StyleSheet, Text, View } from 'react-native';
const onSelect = props => el => {
props.actions.changeTab({
from: props.activeTab,
name: el.props.name,
navigator: props.navigator,
});
return {
selectionColor: props.tabStyles.tint || '#037AFF',
};
};
const imageStyle = props => ({
height: 25,
resizeMode: 'contain',
tintColor: props.selectionColor || '#929292',
width: 30,
});
const tabBarStyle = props => ({
backgroundColor: props.tabStyles.barTint || '#F9F9F9',
borderTopColor: '#D8D8D8',
borderTopWidth: 1,
});
const tabContainerStyle = () => ({
alignItems: 'center',
justifyContent: 'center',
});
const textStyle = props => ({
color: props.selectionColor || '#929292',
fontSize: 10,
letterSpacing: 0.2,
marginBottom: 2,
marginTop: 4,
});
class TabBarIcon extends Component {
render() {
const { name, tabItem } = this.props;
return (
<View name={name} style={tabContainerStyle()}>
{tabItem.icon &&
<Image
source={tabItem.icon}
style={imageStyle(this.props)}
/>
}
{tabItem.title &&
<Text style={textStyle(this.props)}>{tabItem.title}</Text>
}
</View>
);
}
}
export default class TabBar extends Component {
constructor(props){
super(props);
this.state = {};
}
render() {
const { tabs } = this.props;
const tabBarItems = Object.keys(tabs).map(tabName => {
const tab = tabs[tabName];
const tabItem = tab.tabItem || {};
return (
<TabBarIcon
key={tabName}
name={tabName}
tabItem={tabItem}
tabStyles={this.props.tabStyles}
/>
);
});
return (
<Tabs
activeOpacity={1.0}
onSelect={onSelect(this.props)}
selected={this.props.activeTab}
style={tabBarStyle(this.props)}
>
{tabBarItems}
</Tabs>
);
}
}
|
src/components/Alert.js
|
Grilados/site
|
import React, { Component } from 'react';
import './css/Alert.css';
export class Alert extends Component {
render() {
return(
<div className="alert">
<div className="text-center title"> {this.props.title} </div>
<div className="text-center body"> {this.props.body} </div>
</div>
)
}
}
|
src/components/Router/TabIcon/index.js
|
topguru/React-Equiaction
|
import React from 'react';
import {Text, View, Image} from 'react-native';
import { Scene, Router, Actions, TabBar } from 'react-native-router-flux';
import { images } from '../../../theme';
import styles from './style';
const HomeTabIcon = (props) => (
<View style={styles.tabIconView}>
<Image source={props.selected ? images.HomeActive: images.HomeInactive} />
<Text style={{ fontSize: 11, color: props.selected ? 'blue': 'black'}} >{props.title}</Text>
</View>
);
const CataTabIcon = (props) => (
<View style={styles.tabIconView}>
<Image source={props.selected ? images.CatalogueActive: images.CatalogueInactive} />
<Text style={{ fontSize: 11, color: props.selected ? 'blue': 'black'}} >{props.title}</Text>
</View>
);
const AdsTabIcon = (props) => (
<View style={styles.tabIconView}>
<Image source={props.selected ? images.AdsActive: images.AdsInactive} />
<Text style={{ fontSize: 11, color: props.selected ? 'blue': 'black'}} >{props.title}</Text>
</View>
);
const FavTabIcon = (props) => (
<View style={styles.tabIconView}>
<Image source={props.selected ? images.FavoriteActive: images.FavoriteInactive} />
<Text style={{ fontSize: 11, color: props.selected ? 'blue': 'black'}} >{props.title}</Text>
</View>
);
const ProTabIcon = (props) => (
<View style={styles.tabIconView}>
<Image source={props.selected ? images.ProfileActive: images.ProfileInactive} />
<Text style={{ fontSize: 11, color: props.selected ? 'blue': 'black'}} >{props.title}</Text>
</View>
);
export {HomeTabIcon , CataTabIcon , AdsTabIcon , FavTabIcon , ProTabIcon};
|
example/TestLibQuickblox/IndicatorDialog.js
|
ttdat89/react-native-video-quickblox
|
/**
* Created by Dat Tran on 1/25/17.
*/
import React from 'react'
import {View, Text, StyleSheet, Modal, TouchableOpacity} from 'react-native'
import Spinner from 'react-native-spinkit'
import PropTypes from 'prop-types'
export default class IndicatorDialog extends React.Component {
static propTypes = {
message: PropTypes.string.isRequired,
}
constructor(props) {
super(props);
this.state = {
modalVisible: true
}
}
render() {
const {message, showGlobalIndicator} = this.props;
return (
<View>
<Modal animationType='fade'
transparent={true}
visible={true}
onRequestClose={() => {
console.log('android click back')
}}>
<View style={[styles.container, {backgroundColor: 'rgba(0, 0, 0, 0.2)'}]}>
<View style={[styles.innerContainer]}>
<Spinner isVisible={true}
size={60}
type='ThreeBounce'
color='#4286f4'/>
<Text>{message}</Text>
</View>
</View>
</Modal>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
innerContainer: {
borderRadius: 10,
alignItems: 'center',
backgroundColor: '#fff',
paddingBottom: 20,
width: 280
},
row: {
alignItems: 'center',
flex: 1,
flexDirection: 'row',
marginBottom: 20,
},
rowTitle: {
flex: 1,
fontWeight: 'bold',
},
button: {
borderRadius: 5,
flex: 1,
height: 44,
alignSelf: 'stretch',
justifyContent: 'center',
overflow: 'hidden',
},
buttonText: {
fontSize: 18,
margin: 5,
textAlign: 'center',
color: 'white'
},
modalButton: {
borderRadius: 4,
marginTop: 10,
padding: 4,
backgroundColor: 'orange'
},
});
|
src/svg-icons/action/pregnant-woman.js
|
barakmitz/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let ActionPregnantWoman = (props) => (
<SvgIcon {...props}>
<path d="M9 4c0-1.11.89-2 2-2s2 .89 2 2-.89 2-2 2-2-.89-2-2zm7 9c-.01-1.34-.83-2.51-2-3 0-1.66-1.34-3-3-3s-3 1.34-3 3v7h2v5h3v-5h3v-4z"/>
</SvgIcon>
);
ActionPregnantWoman = pure(ActionPregnantWoman);
ActionPregnantWoman.displayName = 'ActionPregnantWoman';
ActionPregnantWoman.muiName = 'SvgIcon';
export default ActionPregnantWoman;
|
app/components/Keys/Add.js
|
soosgit/vessel
|
// @flow
import React, { Component } from 'react';
import { Redirect } from 'react-router';
import { Button, Divider, Grid, Header, Segment } from 'semantic-ui-react';
import KeysGenerate from './Generate';
import KeysImport from './Import';
import KeysLogin from './Login';
import KeysCreate from './Create';
export default class Welcome extends Component {
state = {
importMethod: false
}
handleMethodChange = (e, props) => this.setState({ importMethod: props.value })
handleMethodReset = (e, props) => this.setState({ importMethod: false })
render() {
let display = (
<Segment.Group>
<Segment padded>
<Header>
Import a steemit.com account
<Header.Subheader>
By using your steemit.com username and password, your private
keys can be derived and imported into your wallet.
</Header.Subheader>
</Header>
<Button
color="green"
size="large"
onClick={this.handleMethodChange}
value="login-steemit"
>
Import a steemit.com account
</Button>
</Segment>
<Segment padded>
<Header>
Import a private key
<Header.Subheader>
Any type of private key can be imported into your wallet,
granting different levels of permission based on the key used.
</Header.Subheader>
</Header>
<Button
color="green"
size="large"
onClick={this.handleMethodChange}
value="import-private-key"
>
Import a private key
</Button>
</Segment>
<Segment padded>
<Header>
Experimental - Generate New Private Keys
<Header.Subheader>
For advanced users.
Create a new set of public and private keys for a new Steem
account. These <strong>public</strong> keys can then be given
to another user or service allowing the creation of an account.
</Header.Subheader>
</Header>
<Button
color="black"
size="large"
onClick={this.handleMethodChange}
value="generate-private-key"
>
Generate new private keys
</Button>
</Segment>
</Segment.Group>
);
switch (this.state.importMethod) {
case 'import-private-key':
display = (
<KeysImport
handleMethodReset={this.handleMethodReset}
{...this.props}
/>
);
break;
case 'login-steemit':
display = (
<KeysLogin
handleMethodReset={this.handleMethodReset}
{...this.props}
/>
);
break;
case 'generate-private-key':
display = (
<KeysGenerate
handleMethodReset={this.handleMethodReset}
{...this.props}
/>
);
break;
default: {
break;
}
}
return display;
}
}
|
node_modules/react-router/es6/IndexLink.js
|
igMartin/Redux-Tinder
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
import React from 'react';
import Link from './Link';
/**
* An <IndexLink> is used to link to an <IndexRoute>.
*/
var IndexLink = React.createClass({
displayName: 'IndexLink',
render: function render() {
return React.createElement(Link, _extends({}, this.props, { onlyActiveOnIndex: true }));
}
});
export default IndexLink;
|
packages/core/__deprecated__/Grid/index.js
|
romelperez/arwes
|
import React from 'react';
import withStyles from '../tools/withStyles';
import Grid from './Grid';
import styles from './styles';
const GridWithStyles = withStyles(styles)(Grid);
export const Row = props => <GridWithStyles row {...props} />;
export const Col = props => <GridWithStyles col {...props} />;
export default GridWithStyles;
|
src/svg-icons/av/mic-none.js
|
lawrence-yu/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let AvMicNone = (props) => (
<SvgIcon {...props}>
<path d="M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm-1.2-9.1c0-.66.54-1.2 1.2-1.2.66 0 1.2.54 1.2 1.2l-.01 6.2c0 .66-.53 1.2-1.19 1.2-.66 0-1.2-.54-1.2-1.2V4.9zm6.5 6.1c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z"/>
</SvgIcon>
);
AvMicNone = pure(AvMicNone);
AvMicNone.displayName = 'AvMicNone';
AvMicNone.muiName = 'SvgIcon';
export default AvMicNone;
|
examples/flux-utils-todomvc/js/app.js
|
kiopl/flux
|
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
import React from 'react';
import TodoApp from './components/TodoApp.react';
React.render(<TodoApp />, document.getElementById('todoapp'));
|
tests/components/HelpTabs.spec.js
|
trussworks/DoDidDone
|
import React from 'react';
import { HelpTabs } from 'components/HelpTabs';
import { shallow } from 'enzyme';
describe('(Component) HelpTabs', () => {
let _wrapper;
beforeEach(() => _wrapper = shallow(<HelpTabs/>));
it('Renders a help tab container', () => {
const tabsContainer = _wrapper.find('Tabs');
expect(tabsContainer).to.exist;
});
});
|
src/Slider/index.js
|
szchenghuang/react-mdui
|
'use strict';
import React from 'react';
import PropTypes from 'prop-types';
import ClassNames from 'classnames';
import mdui from '../index';
class Slider extends React.Component {
componentDidMount() {
mdui.updateSliders( this.root );
}
render() {
const {
className,
step,
min,
max,
value,
discrete,
disabled,
onChange,
...restProps
} = this.props;
const clx = ClassNames({
...( className && { [ className ]: true } ),
'mdui-slider': true,
'mdui-slider-discrete': discrete
});
const props = {
...restProps,
className: clx,
ref: node => this.root = node
};
const childProps = {
type: 'range',
step,
min,
max,
value,
...( disabled && { disabled: true } ),
onChange: event => onChange( event.target.value )
};
return (
<label { ...props }>
<input { ...childProps } />
</label>
);
}
}
Slider.propTypes = {
style: PropTypes.object,
className: PropTypes.string,
step: PropTypes.number,
min: PropTypes.number,
max: PropTypes.number,
value: PropTypes.number,
discrete: PropTypes.any,
disabled: PropTypes.any,
onChange: PropTypes.func
};
Slider.defaultProps = {
step: 1,
min: 0,
max: 100,
onChange: () => {}
};
export default Slider;
|
src/Stepper/StepButton.spec.js
|
rscnt/material-ui
|
/* eslint-env mocha */
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import sinon from 'sinon';
import StepButton from './StepButton';
import getMuiTheme from '../styles/getMuiTheme';
describe('<StepButton />', () => {
const muiTheme = getMuiTheme();
const themedShallow = (node) => {
const context = {muiTheme, stepper: {orientation: 'horizontal'}};
return shallow(node, {context});
};
it('merges user styles in', () => {
const wrapper = themedShallow(
<StepButton style={{backgroundColor: 'purple'}}>Step One</StepButton>
);
assert.strictEqual(wrapper.props().style.backgroundColor, 'purple');
});
it('renders an EnhancedButton with a StepLabel', () => {
const wrapper = themedShallow(
<StepButton>Step One</StepButton>
);
assert.ok(wrapper.is('EnhancedButton'));
const stepLabel = wrapper.find('StepLabel');
assert.strictEqual(stepLabel.length, 1);
assert.strictEqual(stepLabel.props().children, 'Step One');
});
it('passes props to StepLabel', () => {
const wrapper = themedShallow(
<StepButton
active={true}
completed={true}
disabled={true}
label="Step One"
>
Step One
</StepButton>
);
const stepLabel = wrapper.find('StepLabel');
assert.strictEqual(stepLabel.prop('active'), true);
assert.strictEqual(stepLabel.prop('completed'), true);
assert.strictEqual(stepLabel.prop('disabled'), true);
});
it('passes props to EnhancedButton', () => {
const wrapper = themedShallow(
<StepButton disabled={true}>Step One</StepButton>
);
const stepLabel = wrapper.find('EnhancedButton');
assert.strictEqual(stepLabel.prop('disabled'), true);
});
it('bubbles callbacks used internally', () => {
const handleMouseEnter = sinon.spy();
const handleMouseLeave = sinon.spy();
const handleTouchStart = sinon.spy();
const wrapper = themedShallow(
<StepButton
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onTouchStart={handleTouchStart}
>
Step One
</StepButton>
);
wrapper.simulate('mouseEnter');
assert.ok(handleMouseEnter.calledOnce);
wrapper.simulate('mouseLeave');
assert.ok(handleMouseEnter.calledOnce);
assert.ok(handleMouseLeave.calledOnce);
wrapper.simulate('touchStart');
assert.ok(handleMouseEnter.calledOnce);
assert.ok(handleMouseLeave.calledOnce);
assert.ok(handleTouchStart.calledOnce);
wrapper.simulate('mouseEnter');
wrapper.simulate('touchStart');
assert.ok(handleMouseEnter.calledTwice);
assert.ok(handleMouseLeave.calledOnce);
assert.ok(handleTouchStart.calledTwice);
});
it('sets the EnhancedButton backgroundColor on hover', () => {
const wrapper = themedShallow(
<StepButton>Step One</StepButton>
);
assert.strictEqual(wrapper.prop('style').backgroundColor, muiTheme.stepper.backgroundColor);
wrapper.setState({hovered: true});
assert.strictEqual(wrapper.prop('style').backgroundColor, muiTheme.stepper.hoverBackgroundColor);
});
});
|
packages/material-ui-icons/src/ExitToApp.js
|
cherniavskii/material-ui
|
import React from 'react';
import createSvgIcon from './utils/createSvgIcon';
export default createSvgIcon(
<g><path d="M10.09 15.59L11.5 17l5-5-5-5-1.41 1.41L12.67 11H3v2h9.67l-2.58 2.59zM19 3H5c-1.11 0-2 .9-2 2v4h2V5h14v14H5v-4H3v4c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" /></g>
, 'ExitToApp');
|
app/src/components/achievements/AchievementsOverview.js
|
kort/kort-native
|
import React, { Component } from 'react';
import {
View,
ListView,
RefreshControl
} from 'react-native';
import { connect } from 'react-redux';
import _ from 'lodash';
import I18n from 'react-native-i18n';
import AchievementItem from './AchievementItem';
import { downloadAchievements, clearErrorMsg } from '../../actions/AchievementsActions';
import { forceViewUpdateAchievements } from '../../actions/NavigationActions';
import { Spinner, Popup } from '../common';
class AchievementsOverview extends Component {
componentWillMount() {
this.props.downloadAchievements(false, this.props.user.id);
}
componentWillReceiveProps(nextProps) {
if (nextProps.updateAchievementsView) {
this.props.downloadAchievements(false, this.props.user.id);
this.props.forceViewUpdateAchievements(false);
}
}
onAccept() {
this.props.clearErrorMsg();
}
onRefresh() {
this.props.downloadAchievements(true, this.props.user.id);
}
renderRow(rowData) {
if (_.isEmpty(rowData)) {
return <View style={styles.itemStyle} />;
}
return <AchievementItem achievement={rowData} />;
}
renderSpinner() {
if (this.props.downloading) {
return (
<Spinner
size='large'
style={styles.spinnerStyle}
/>
);
}
return null;
}
render() {
return (
<View style={styles.bgColor}>
{this.renderSpinner()}
<ListView
contentContainerStyle={styles.list}
dataSource={this.props.dataSource}
renderRow={(rowData) => this.renderRow(rowData)}
initialListSize={15}
enableEmptySections
refreshControl={
<RefreshControl
refreshing={this.props.loading}
onRefresh={this.onRefresh.bind(this)}
colors={['#202931', 'white']}
tintColor='white'
/>}
/>
<Popup
visible={this.props.errorMsg !== null}
onAccept={this.onAccept.bind(this)}
message={I18n.t('error_message_bad_connectivity')}
/>
</View>
);
}
}
const styles = {
bgColor: {
backgroundColor: '#202931',
flex: 1,
paddingTop: 60,
paddingBottom: 50,
},
list: {
paddingTop: 10,
paddingBottom: 10,
justifyContent: 'center',
flexDirection: 'row',
flexWrap: 'wrap',
},
itemStyle: {
margin: 5,
height: 100,
width: 100
},
spinnerStyle: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
justifyContent: 'center',
alignItems: 'center'
}
};
const dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
});
const mapStateToProps = ({ achievementsReducer, authReducer, navigationReducer }) => {
const { user } = authReducer;
const { achievements, loading, downloading, errorMsg } = achievementsReducer;
const { updateAchievementsView } = navigationReducer;
return {
dataSource: dataSource.cloneWithRows(achievements),
loading,
downloading,
errorMsg,
user,
updateAchievementsView
};
};
export default connect(mapStateToProps, {
downloadAchievements, clearErrorMsg, forceViewUpdateAchievements })(AchievementsOverview);
|
__tests__/components/Image-test.js
|
linde12/grommet
|
// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
import React from 'react';
import renderer from 'react-test-renderer';
import Image from '../../src/js/components/Image';
describe('Image', () => {
it('has correct default options', () => {
const component = renderer.create(
<Image src="test.png" data-flavor="coconut" />
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
it('has correct size="thumb" rendering', () => {
const component = renderer.create(
<Image src='test.png' size='thumb' />
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
it('has correct full="horizontal" and caption rendering', () => {
const component = renderer.create(
<Image src='test.png' caption='Testing' full='horizontal' />
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
});
|
client/src/index.js
|
ASU-CodeDevils/DemonHacks2017
|
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
|
src/index.js
|
Gertrido/test-task-hypermethod
|
import React from 'react'
import {render} from 'react-dom'
import {Provider} from 'react-redux'
import configureStore from './store/configureStore'
import App from './containers/App'
const store = configureStore()
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
|
test/js/AR/arNodeTest.js
|
viromedia/viro
|
/**
* Copyright (c) 2017-present, Viro Media, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import {
ViroARScene,
ViroARPlane,
ViroMaterials,
ViroImage,
ViroARPlaneSelector,
ViroQuad,
ViroConstants,
ViroARNode,
ViroBox,
} from 'react-viro';
import TimerMixin from 'react-timer-mixin';
var createReactClass = require('create-react-class');
var testARScene = createReactClass({
mixins: [TimerMixin],
getInitialState: function() {
return {
text : "not tapped",
visible: true,
everythingVisible: false,
success: false,
video : "",
}
},
render: function() {
return (
<ViroARScene >
<ViroARNode position={[0,0,-1]} onDrag={()=>{}}>
<ViroBox position={[0,.13,0]} scale={[.2,.2,.2]} />
<ViroImage rotation={[-90,0,0]} scale={[.3,.3,.3]}
source={require('./res/dark_circle_shadow.png')}/>
</ViroARNode>
</ViroARScene>
);
},
});
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#FFFFFF',
},
welcome: {
fontSize: 13,
textAlign: 'center',
color: '#ffffff',
margin: 2,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
ViroMaterials.createMaterials({
blue: {
shininess: 2.0,
lightingModel: "Lambert",
diffuseColor: "#0000ff"
},
black: {
shininess: 2.0,
lightingModel: "Lambert",
diffuseColor: "#000000"
},
red: {
shininess: 2.0,
lightingModel: "Constant",
diffuseColor: "#ff0000"
},
green: {
shininess: 2.0,
lightingModel: "Constant",
diffuseColor: "#00ff00"
},
});
module.exports = testARScene;
|
src/index.js
|
JonKruger/openspaces-react
|
/* eslint-disable import/default */
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import routes from './routes';
import configureStore from './app/store/configureStore';
require('./favicon.ico'); // Tell webpack to load favicon.ico
import './app/styles/styles.scss'; // Yep, that's right. You can import SASS/CSS files too! Webpack will run the associated loader and plug this into the page.
import { syncHistoryWithStore } from 'react-router-redux';
// import {loadSessionListData} from './actions/SessionActions';
const store = configureStore();
// Create an enhanced history that syncs navigation events with the store
const history = syncHistoryWithStore(browserHistory, store);
render(
<Provider store={store}>
<Router history={history} routes={routes} />
</Provider>, document.getElementById('app')
);
|
src/layouts/index.js
|
adrienlozano/stephaniewebsite
|
import React from 'react';
import Header from '~/components/header';
import Footer from '~/components/footer';
import { setDisplayName, compose, defaultProps } from 'recompose';
import { injectGlobal } from 'styled-components'
import Head from 'react-helmet';
import { ThemeProvider } from 'styled-components';
import { Flex } from 'rebass';
import { Provider } from 'rebass';
import 'normalize.css';
import "react-responsive-carousel/lib/styles/carousel.css";
import 'mdi/css/materialdesignicons.css';
import 'typeface-roboto-slab';
import 'typeface-roboto';
import theme from "~/app/theme";
injectGlobal`
* { box-sizing: border-box; }
body, html, #PhenomicRoot, #PhenomicRoot > div {
height: 100%;
}
`
const Body = ({children}) => (<div>{children}</div>);
var Layout = ({children}) =>{
return (
<Provider theme={theme}>
<Head>
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</Head>
<div style={{height: "100%" }}>
<Header/>
<Body>{children()}</Body>
<Footer/>
</div>
</Provider>
);
}
var enhance = compose(
setDisplayName('Layout')
);
export default enhance(Layout);
export { Layout };
|
definitions/npm/@kadira/storybook_v1.x.x/test_storybook_v1.x.x.js
|
mkscrg/flow-typed
|
// @flow
import React from 'react';
import { action, storiesOf } from '@kadira/storybook';
storiesOf('div', module)
.add('empty', () => (
<div onClick={action('click')} />
))
// $ExpectError
.aad('empty', () => (
<div />
));
|
src/containers/camper.js
|
chrischavarro/CamperLeaderboard
|
import React from 'react';
export default (props) => {
return (
<tr>
<td>{props.index+1}</td>
<td>
<img src={props.data.img} className="camperAvatar" />
<a href={props.data.camperURL}>{props.data.username}</a>
</td>
<td>{props.data.recent}</td>
<td>{props.data.alltime}</td>
</tr>
)
}
|
src/esm/components/graphics/icons-next/people-icon-next/index.js
|
KissKissBankBank/kitten
|
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["color", "title"];
import React from 'react';
import PropTypes from 'prop-types';
export var PeopleIconNext = function PeopleIconNext(_ref) {
var color = _ref.color,
title = _ref.title,
props = _objectWithoutPropertiesLoose(_ref, _excluded);
return /*#__PURE__*/React.createElement("svg", _extends({
width: "10",
height: "12",
fill: "none",
viewBox: "0 0 10 12",
xmlns: "http://www.w3.org/2000/svg"
}, props), title && /*#__PURE__*/React.createElement("title", null, title), /*#__PURE__*/React.createElement("path", {
fill: color,
fillRule: "evenodd",
d: "M5 6a3 3 0 100-6 3 3 0 000 6zm0 6c2.761 0 5-.714 5-.714C10 8.919 7.761 7 5 7s-5 1.919-5 4.286c0 0 2.239.714 5 .714z",
clipRule: "evenodd"
}));
};
PeopleIconNext.propTypes = {
color: PropTypes.string,
title: PropTypes.string
};
PeopleIconNext.defaultProps = {
color: '#222',
title: null
};
|
stories/Slider/index.js
|
nirhart/wix-style-react
|
import React from 'react';
import {storiesOf} from '@kadira/storybook';
import Markdown from '../utils/Components/Markdown';
import CodeExample from '../utils/Components/CodeExample';
import Readme from '../../src/Slider/README.md';
import ExampleStandard from './ExampleStandard';
import ExampleStandardRaw from '!raw!./ExampleStandard';
import ExampleControlled from './ExampleControlled';
import ExampleControlledRaw from '!raw!./ExampleControlled';
import ExampleRtl from './ExampleRtl';
import ExampleRtlRaw from '!raw!./ExampleRtl';
storiesOf('Core', module)
.add('Slider', () => (
<div>
<Markdown source={Readme}/>
<h1>Usage examples</h1>
<CodeExample title="Standard" code={ExampleStandardRaw}>
<ExampleStandard/>
</CodeExample>
<CodeExample title="Standard RTL" code={ExampleRtlRaw}>
<ExampleRtl/>
</CodeExample>
<CodeExample title="Controlled input" code={ExampleControlledRaw}>
<ExampleControlled/>
</CodeExample>
</div>
));
|
src/components/fragment/Header/index.js
|
luanhaipeng/coolpeng-react
|
import React from 'react'
import './index.less'
import {Link} from 'react-router'
export default class Header extends React.Component {
constructor(props) {
super(props)
}
renderRightLogin(){
const {user} = this.props;
var userInfo = user.user;
if(userInfo && user.isLogged){
return (
<div>
欢迎您:{userInfo.nickname}
<span onClick={this.props.onClickLogout}>退出</span>
</div>
);
}
return (
<div>
<span>注册</span> /
<span onClick={this.props.onClickLogin}>登录</span>
</div>);
}
render() {
return (
<div className='ant-layout-header'>
<div className='page-content'>
<h1 className="my-logo float-l" >
<Link to="/home">
<span className="text">coolpeng</span>
</Link>
</h1>
<Link to="/home">
home
</Link>
<Link to="/daohang">
daohang
</Link>
<div className="float-l">
</div>
<div className="float-r login-btn">
{this.renderRightLogin()}
</div>
<div className="clear"></div>
</div>
</div>
)
}
}
|
src/library/Icon/__tests__/Icon.theme.spec.js
|
mineral-ui/mineral-ui
|
/**
* @jest-environment node
*/
/* @flow */
import React from 'react';
import testThemeOverrides from '../../../../utils/testThemeOverrides';
import Icon from '../Icon';
describe('Icon', () => {
describe('theme overrides', () => {
testThemeOverrides(<Icon />, ['Icon_fill', 'Icon_size_medium']);
testThemeOverrides(<Icon size="small" />, ['Icon_size_small']);
testThemeOverrides(<Icon size="large" />, ['Icon_size_large']);
});
});
|
example/screens/TrumpSortScreen.js
|
GantMan/useless-things
|
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { TrumpSort } from 'useless-things'
const LENGTH = 15
const randomArray = () => [...new Array(LENGTH)]
.map(() => Math.round(Math.random() * 99))
export default class App extends React.Component {
render () {
const currentArray = randomArray()
return (
<View style={styles.container}>
<Text style={styles.title}>Examples of Trump Sort</Text>
<Text style={styles.thing}>Trump Sort Random Array</Text>
<Text style={styles.text}>
Random Array: {'\n' + currentArray + '\n\n'}
Trump Sorted: {TrumpSort(currentArray) + '\n'}
</Text>
<Text style={[styles.title, {backgroundColor: 'rgba(0,0,0,0.4)'}]} onPress={() => this.forceUpdate()}>
YUGE TRUMP SORT
</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#333',
alignItems: 'center',
justifyContent: 'center'
},
title: {
fontSize: 20,
fontWeight: 'bold',
color: 'red',
padding: 10
},
thing: {
fontSize: 18,
color: '#fff',
paddingTop: 40
},
text: {
color: '#ccc'
}
})
|
es/Input/InputAdornment.js
|
uplevel-technology/material-ui-next
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import React from 'react';
import classNames from 'classnames';
import Typography from '../Typography';
import withStyles from '../styles/withStyles';
export const styles = theme => ({
root: {
'label + div > &': {
marginTop: -theme.spacing.unit * 2,
height: 26
}
},
positionStart: {
marginRight: theme.spacing.unit
},
positionEnd: {
marginLeft: theme.spacing.unit
}
});
class InputAdornment extends React.Component {
render() {
const _props = this.props,
{
children,
component: Component,
classes,
className,
disableTypography,
position
} = _props,
other = _objectWithoutProperties(_props, ['children', 'component', 'classes', 'className', 'disableTypography', 'position']);
return React.createElement(
Component,
_extends({
className: classNames(classes.root, {
[classes.positionStart]: position === 'start',
[classes.positionEnd]: position === 'end'
}, className)
}, other),
typeof children === 'string' && !disableTypography ? React.createElement(
Typography,
{ color: 'secondary' },
children
) : children
);
}
}
InputAdornment.defaultProps = {
component: 'div',
disableTypography: false
};
export default withStyles(styles, { name: 'MuiInputAdornment' })(InputAdornment);
|
packages/callout/src/js/react.js
|
govau/uikit
|
/*! [replace-name] v[replace-version] */
/***************************************************************************************************************************************************************
*
* Callout function
*
* Use callout to notify and alert users of important snippets of information.
*
**************************************************************************************************************************************************************/
import React from 'react';
import PropTypes from 'prop-types';
// The following line will be replaced automatically with generic imports for the ES5 pipeline.
// You can safely ignore this bit if you use this module with pancake
//
// [replace-imports]
/**
* Default callout
*
* @param {string} title - The title of the header
* @param {string} level - The tag level (<h1/> <h2/> etc), default: '1'
* @param {boolean} srOnlyTitle - Title is visible to screen readers only
* @param {boolean} dark - Add the dark variation class, optional
* @param {boolean} alt - Add the alt variation class, optional
* @param {string} children - Anything inside
* @param {string} className - An additional class, optional
* @param {object} attributeOptions - Any other attribute options
*/
export const AUcallout = ({ title, level, srOnlyTitle, dark, alt, description, children, className = '', ...attributeOptions }) => {
const HeadingTag = `h${ level }`;
return (
<section
className={ `au-callout ${ className }${ dark ? ' au-callout--dark' : '' }${ alt ? ' au-callout--alt' : '' }` }
{ ...attributeOptions }
>
<HeadingTag
children={ title }
className={ `au-callout__heading${ srOnlyTitle ? ' au-callout__heading--sronly' : '' }` }
/>
{ children }
</section>
)
};
AUcallout.propTypes = {
title: PropTypes.string.isRequired,
level: PropTypes.number,
srOnlyTitle: PropTypes.bool,
dark: PropTypes.bool,
alt: PropTypes.bool,
children: PropTypes.node.isRequired,
className: PropTypes.string,
};
AUcallout.defaultProps = {
level: 2,
srOnlyTitle: false,
};
/**
* Calendar callout
*
* @param {string} title - The title of the header
* @param {string} level - The tag level (<h1/> <h2/> etc), default: '1'
* @param {boolean} srOnlyTitle - Title is visible to screen readers only
* @param {boolean} dark - Add the dark variation class, optional
* @param {boolean} alt - Add the alt variation class, optional
* @param {string} subline - The subline of the event, optional
* @param {string} datetime - The datetime of the event as ISO datetime
* @param {string} time - The time that appears on the page
* @param {string} name - The name of the event, optional
* @param {string} className - An additional class, optional
* @param {object} attributeOptions - Any other attribute options
*/
export const AUcalloutCalendar = ({ title, level, srOnlyTitle, dark, alt, subline, datetime, time, name, className = '', ...attributeOptions }) => {
const HeadingTag = `h${ level }`;
return (
<section
className={ `au-callout au-callout--calendar-event ${ className }${ dark ? ' au-callout--dark' : '' }${ alt ? ' au-callout--alt' : '' }` }
{ ...attributeOptions }
>
<HeadingTag
children={ title }
className={ `au-callout__heading${ srOnlyTitle ? ' au-callout__heading--sronly' : '' }` }
/>
{ subline && <p className="au-callout--calendar-event__lede">{ subline }</p> }
<time className="au-callout--calendar-event__time" dateTime={ new Date( datetime ).toJSON() }>{ time }</time>
{ name && <span className="au-callout--calendar-event__name">{ name }</span> }
</section>
)
}
AUcalloutCalendar.propTypes = {
title: PropTypes.string.isRequired,
level: PropTypes.number,
srOnlyTitle: PropTypes.bool,
dark: PropTypes.bool,
alt: PropTypes.bool,
subline: PropTypes.string,
datetime: PropTypes.string.isRequired,
time: PropTypes.string.isRequired,
name: PropTypes.string,
className: PropTypes.string,
};
AUcalloutCalendar.defaultProps = {
level: 2,
srOnlyTitle: true,
};
|
src/svg-icons/content/markunread.js
|
w01fgang/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let ContentMarkunread = (props) => (
<SvgIcon {...props}>
<path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/>
</SvgIcon>
);
ContentMarkunread = pure(ContentMarkunread);
ContentMarkunread.displayName = 'ContentMarkunread';
ContentMarkunread.muiName = 'SvgIcon';
export default ContentMarkunread;
|
components/TodoForm.js
|
bobbyangelov/3things
|
import React from 'react';
import ReactDOM from 'react-dom';
class TodoForm extends React.Component {
constructor() {
super();
this.state = {
text: ''
};
}
handleSubmit(e) {
e.preventDefault();
this.props.addItem(this.refs.todoField.value);
this.setState({text: ''});
this.refs.todoField.value = '';
}
handleChange(e) {
this.setState({
text: e.target.value
})
}
isDisabled() {
return this.props.items.length > 2 || !this.state.text.length ? true : false
}
render() {
const disabled = this.isDisabled();
return (
<div>
<form onSubmit={this.handleSubmit.bind(this)} className="form-inline">
<input type="text" ref="todoField" onChange={this.handleChange.bind(this)} />
<input type="submit" value="+ Add" className="btn btn-primary" disabled={disabled}/>
</form>
</div>
);
}
}
export default TodoForm
|
src/app/routes.js
|
mischlecht/HackWeekend2017-react-app
|
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import App from './app.jsx';
import HomeController from '../home/home.controller.jsx';
import ImagesController from '../images/images.controller.jsx';
import NotFoundPage from '../shared/components/not-found-page.jsx';
export default (
<Route path="/" component={App}>
<IndexRoute component={HomeController}/>
<Route path="images" component={ImagesController}/>
<Route path="*" component={NotFoundPage}/>
</Route>
);
|
test/Utils-spec.js
|
toddw/enzyme
|
import { describeWithDOM } from './_helpers.js';
import React from 'react';
import { expect } from 'chai';
import { mount } from '../src/';
import {
coercePropValue,
getNode,
nodeEqual,
isSimpleSelector,
propFromEvent,
SELECTOR,
selectorType,
mapNativeEventNames,
} from '../src/Utils';
describe('Utils', () => {
describeWithDOM('getNode', () => {
it('should return a DOMNode when a DOMComponent is given', () => {
const div = mount(<div />).node;
expect(getNode(div)).to.be.instanceOf(window.HTMLElement);
});
it('should return the component when a component is given', () => {
class Foo extends React.Component {
render() { return <div />; }
}
const foo = mount(<Foo />).node;
expect(getNode(foo)).to.equal(foo);
});
});
describe('nodeEqual', () => {
it('should match empty elements of same tag', () => {
expect(nodeEqual(
<div />,
<div />
)).to.equal(true);
});
it('should not match empty elements of different type', () => {
expect(nodeEqual(
<div />,
<nav />
)).to.equal(false);
});
it('should match basic prop types', () => {
expect(nodeEqual(
<div className="foo" />,
<div className="foo" />
)).to.equal(true);
expect(nodeEqual(
<div id="foo" className="bar" />,
<div id="foo" className="bar" />
)).to.equal(true);
expect(nodeEqual(
<div id="foo" className="baz" />,
<div id="foo" className="bar" />
)).to.equal(false);
});
it('should check children as well', () => {
expect(nodeEqual(
<div>
<div />
</div>,
<div />
)).to.equal(false);
expect(nodeEqual(
<div>
<div />
</div>,
<div>
<div />
</div>
)).to.equal(true);
expect(nodeEqual(
<div>
<div className="foo" />
</div>,
<div>
<div className="foo" />
</div>
)).to.equal(true);
expect(nodeEqual(
<div>
<div className="foo" />
</div>,
<div>
<div />
</div>
)).to.equal(false);
});
it('should test deepEquality with object props', () => {
expect(nodeEqual(
<div foo={{ a: 1, b: 2 }} />,
<div foo={{ a: 1, b: 2 }} />
)).to.equal(true);
expect(nodeEqual(
<div foo={{ a: 2, b: 2 }} />,
<div foo={{ a: 1, b: 2 }} />
)).to.equal(false);
});
});
describe('propFromEvent', () => {
const fn = propFromEvent;
it('should work', () => {
expect(fn('click')).to.equal('onClick');
expect(fn('mouseEnter')).to.equal('onMouseEnter');
});
});
describe('isSimpleSelector', () => {
describe('prohibited selectors', () => {
function isComplex(selector) {
it(selector, () => {
expect(isSimpleSelector(selector)).to.equal(false);
});
}
isComplex('.foo .bar');
isComplex(':visible');
isComplex('.foo>.bar');
isComplex('.foo > .bar');
isComplex('.foo~.bar');
});
describe('allowed selectors', () => {
function isSimple(selector) {
it(selector, () => {
expect(isSimpleSelector(selector)).to.equal(true);
});
}
isSimple('.foo');
isSimple('.foo-and-foo');
isSimple('input[foo="bar"]');
isSimple('input[foo="bar"][bar="baz"][baz="foo"]');
isSimple('.FoOaNdFoO');
isSimple('tag');
isSimple('.foo.bar');
isSimple('input.foo');
});
});
describe('selectorType', () => {
it('returns CLASS_TYPE for a prefixed .', () => {
const type = selectorType('.foo');
expect(type).to.be.equal(SELECTOR.CLASS_TYPE);
});
it('returns ID_TYPE for a prefixed #', () => {
const type = selectorType('#foo');
expect(type).to.be.equal(SELECTOR.ID_TYPE);
});
it('returns PROP_TYPE for []', () => {
function isProp(selector) {
expect(selectorType(selector)).to.be.equal(SELECTOR.PROP_TYPE);
}
isProp('[foo]');
isProp('[foo="bar"]');
});
});
describe('coercePropValue', () => {
const key = 'foo';
it('returns undefined if passed undefined', () => {
expect(coercePropValue(key, undefined)).to.equal(undefined);
});
it('returns number if passed a stringified number', () => {
expect(coercePropValue(key, '1')).to.be.equal(1);
expect(coercePropValue(key, '0')).to.be.equal(0);
});
it('returns a boolean if passed a stringified bool', () => {
expect(coercePropValue(key, 'true')).to.equal(true);
expect(coercePropValue(key, 'false')).to.equal(false);
});
});
describe('mapNativeEventNames', () => {
describe('given an event that isn\'t a mapped', () => {
it('returns the original event', () => {
const result = mapNativeEventNames('click');
expect(result).to.equal('click');
});
});
describe('given a React capitalised mouse event', () => {
it('returns the original event', () => {
const result = mapNativeEventNames('mouseEnter');
expect(result).to.equal('mouseEnter');
});
});
describe('given a native lowercase event', () => {
it('transforms it into the React capitalised event', () => {
const result = mapNativeEventNames('dragenter');
expect(result).to.equal('dragEnter');
});
});
});
});
|
tests/react_modules/es6class-proptypes-module.js
|
samwgoldman/flow
|
/* @flow */
import React from 'react';
import type {Node} from 'react';
class Hello extends React.Component<{name: string}> {
defaultProps = {};
propTypes = {
name: React.PropTypes.string.isRequired,
};
render(): Node {
return <div>{this.props.name}</div>;
}
}
module.exports = Hello;
|
src/svg-icons/editor/insert-link.js
|
lawrence-yu/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let EditorInsertLink = (props) => (
<SvgIcon {...props}>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</SvgIcon>
);
EditorInsertLink = pure(EditorInsertLink);
EditorInsertLink.displayName = 'EditorInsertLink';
EditorInsertLink.muiName = 'SvgIcon';
export default EditorInsertLink;
|
examples/gatsby/src/pages/index.js
|
cherniavskii/material-ui
|
import React from 'react';
import PropTypes from 'prop-types';
import Button from 'material-ui/Button';
import Dialog, {
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
} from 'material-ui/Dialog';
import Typography from 'material-ui/Typography';
import { withStyles } from 'material-ui/styles';
import withRoot from '../withRoot';
const styles = theme => ({
root: {
textAlign: 'center',
paddingTop: theme.spacing.unit * 20,
},
});
class Index extends React.Component {
state = {
open: false,
};
handleClose = () => {
this.setState({
open: false,
});
};
handleClick = () => {
this.setState({
open: true,
});
};
render() {
const { classes } = this.props;
const { open } = this.state;
return (
<div className={classes.root}>
<Dialog open={open} onClose={this.handleClose}>
<DialogTitle>Super Secret Password</DialogTitle>
<DialogContent>
<DialogContentText>1-2-3-4-5</DialogContentText>
</DialogContent>
<DialogActions>
<Button color="primary" onClick={this.handleClose}>
OK
</Button>
</DialogActions>
</Dialog>
<Typography variant="display1" gutterBottom>
Material-UI
</Typography>
<Typography variant="subheading" gutterBottom>
example project
</Typography>
<Button variant="raised" color="secondary" onClick={this.handleClick}>
Super Secret Password
</Button>
</div>
);
}
}
Index.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withRoot(withStyles(styles)(Index));
|
lib/components/Voter.js
|
pguth/puddin
|
import React from 'react'
export default class Voter extends React.Component {
onUpvote(e) {
this.props.onVote(1)
}
onDownvote(e) {
this.props.onVote(-1)
}
render() {
return <div className="voter">
{this.props.vote > 0 ? <div className="up-vote" /> : null}
{this.props.vote === 0 ? <div className="up-vote clickable" onClick={this.onUpvote.bind(this)} /> : null}
<div className="count">{this.props.count}</div>
{this.props.vote === 0 ? <div className="down-vote clickable" onClick={this.onDownvote.bind(this)} /> : null}
{this.props.vote < 0 ? <div className="down-vote" /> : null}
</div>
}
}
|
src/svg-icons/social/plus-one.js
|
ArcanisCz/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let SocialPlusOne = (props) => (
<SvgIcon {...props}>
<path d="M10 8H8v4H4v2h4v4h2v-4h4v-2h-4zm4.5-1.92V7.9l2.5-.5V18h2V5z"/>
</SvgIcon>
);
SocialPlusOne = pure(SocialPlusOne);
SocialPlusOne.displayName = 'SocialPlusOne';
SocialPlusOne.muiName = 'SvgIcon';
export default SocialPlusOne;
|
tests/lib/rules/indent.js
|
eslint/eslint
|
/**
* @fileoverview This option sets a specific tab width for your code
* @author Dmitriy Shekhovtsov
* @author Gyandeep Singh
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/indent"),
{ RuleTester } = require("../../../lib/rule-tester");
const fs = require("fs");
const path = require("path");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const fixture = fs.readFileSync(path.join(__dirname, "../../fixtures/rules/indent/indent-invalid-fixture-1.js"), "utf8");
const fixedFixture = fs.readFileSync(path.join(__dirname, "../../fixtures/rules/indent/indent-valid-fixture-1.js"), "utf8");
const parser = require("../../fixtures/fixture-parser");
const { unIndent } = require("../../_utils");
/**
* Create error message object for failure cases with a single 'found' indentation type
* @param {string} providedIndentType indent type of string or tab
* @param {Array} providedErrors error info
* @returns {Object} returns the error messages collection
* @private
*/
function expectedErrors(providedIndentType, providedErrors) {
let indentType;
let errors;
if (Array.isArray(providedIndentType)) {
errors = Array.isArray(providedIndentType[0]) ? providedIndentType : [providedIndentType];
indentType = "space";
} else {
errors = Array.isArray(providedErrors[0]) ? providedErrors : [providedErrors];
indentType = providedIndentType;
}
return errors.map(err => ({
messageId: "wrongIndentation",
data: {
expected: typeof err[1] === "string" && typeof err[2] === "string"
? err[1]
: `${err[1]} ${indentType}${err[1] === 1 ? "" : "s"}`,
actual: err[2]
},
type: err[3],
line: err[0]
}));
}
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } });
ruleTester.run("indent", rule, {
valid: [
{
code: unIndent`
bridge.callHandler(
'getAppVersion', 'test23', function(responseData) {
window.ah.mobileAppVersion = responseData;
}
);
`,
options: [2]
},
{
code: unIndent`
bridge.callHandler(
'getAppVersion', 'test23', function(responseData) {
window.ah.mobileAppVersion = responseData;
});
`,
options: [2]
},
{
code: unIndent`
bridge.callHandler(
'getAppVersion',
null,
function responseCallback(responseData) {
window.ah.mobileAppVersion = responseData;
}
);
`,
options: [2]
},
{
code: unIndent`
bridge.callHandler(
'getAppVersion',
null,
function responseCallback(responseData) {
window.ah.mobileAppVersion = responseData;
});
`,
options: [2]
},
{
code: unIndent`
function doStuff(keys) {
_.forEach(
keys,
key => {
doSomething(key);
}
);
}
`,
options: [4]
},
{
code: unIndent`
example(
function () {
console.log('example');
}
);
`,
options: [4]
},
{
code: unIndent`
let foo = somethingList
.filter(x => {
return x;
})
.map(x => {
return 100 * x;
});
`,
options: [4]
},
{
code: unIndent`
var x = 0 &&
{
a: 1,
b: 2
};
`,
options: [4]
},
{
code: unIndent`
var x = 0 &&
\t{
\t\ta: 1,
\t\tb: 2
\t};
`,
options: ["tab"]
},
{
code: unIndent`
var x = 0 &&
{
a: 1,
b: 2
}||
{
c: 3,
d: 4
};
`,
options: [4]
},
{
code: unIndent`
var x = [
'a',
'b',
'c'
];
`,
options: [4]
},
{
code: unIndent`
var x = ['a',
'b',
'c',
];
`,
options: [4]
},
{
code: "var x = 0 && 1;",
options: [4]
},
{
code: "var x = 0 && { a: 1, b: 2 };",
options: [4]
},
{
code: unIndent`
var x = 0 &&
(
1
);
`,
options: [4]
},
{
code: unIndent`
require('http').request({hostname: 'localhost',
port: 80}, function(res) {
res.end();
});
`,
options: [2]
},
{
code: unIndent`
function test() {
return client.signUp(email, PASSWORD, { preVerified: true })
.then(function (result) {
// hi
})
.then(function () {
return FunctionalHelpers.clearBrowserState(self, {
contentServer: true,
contentServer1: true
});
});
}
`,
options: [2]
},
{
code: unIndent`
it('should... some lengthy test description that is forced to be' +
'wrapped into two lines since the line length limit is set', () => {
expect(true).toBe(true);
});
`,
options: [2]
},
{
code: unIndent`
function test() {
return client.signUp(email, PASSWORD, { preVerified: true })
.then(function (result) {
var x = 1;
var y = 1;
}, function(err){
var o = 1 - 2;
var y = 1 - 2;
return true;
})
}
`,
options: [4]
},
{
// https://github.com/eslint/eslint/issues/11802
code: unIndent`
import foo from "foo"
;(() => {})()
`,
options: [4],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
function test() {
return client.signUp(email, PASSWORD, { preVerified: true })
.then(function (result) {
var x = 1;
var y = 1;
}, function(err){
var o = 1 - 2;
var y = 1 - 2;
return true;
});
}
`,
options: [4, { MemberExpression: 0 }]
},
{
code: "// hi",
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var Command = function() {
var fileList = [],
files = []
files.concat(fileList)
};
`,
options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }]
},
{
code: " ",
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
if(data) {
console.log('hi');
b = true;};
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
foo = () => {
console.log('hi');
return true;};
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
function test(data) {
console.log('hi');
return true;};
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var test = function(data) {
console.log('hi');
};
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
arr.forEach(function(data) {
otherdata.forEach(function(zero) {
console.log('hi');
}) });
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
a = [
,3
]
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
[
['gzip', 'gunzip'],
['gzip', 'unzip'],
['deflate', 'inflate'],
['deflateRaw', 'inflateRaw'],
].forEach(function(method) {
console.log(method);
});
`,
options: [2, { SwitchCase: 1, VariableDeclarator: 2 }]
},
{
code: unIndent`
test(123, {
bye: {
hi: [1,
{
b: 2
}
]
}
});
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var xyz = 2,
lmn = [
{
a: 1
}
];
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
lmnn = [{
a: 1
},
{
b: 2
}, {
x: 2
}];
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
unIndent`
[{
foo: 1
}, {
foo: 2
}, {
foo: 3
}]
`,
unIndent`
foo([
bar
], [
baz
], [
qux
]);
`,
{
code: unIndent`
abc({
test: [
[
c,
xyz,
2
].join(',')
]
});
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
abc = {
test: [
[
c,
xyz,
2
]
]
};
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
abc(
{
a: 1,
b: 2
}
);
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
abc({
a: 1,
b: 2
});
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var abc =
[
c,
xyz,
{
a: 1,
b: 2
}
];
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var abc = [
c,
xyz,
{
a: 1,
b: 2
}
];
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var abc = 5,
c = 2,
xyz =
{
a: 1,
b: 2
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
unIndent`
var
x = {
a: 1,
},
y = {
b: 2
}
`,
unIndent`
const
x = {
a: 1,
},
y = {
b: 2
}
`,
unIndent`
let
x = {
a: 1,
},
y = {
b: 2
}
`,
unIndent`
var foo = { a: 1 }, bar = {
b: 2
};
`,
unIndent`
var foo = { a: 1 }, bar = {
b: 2
},
baz = {
c: 3
}
`,
unIndent`
const {
foo
} = 1,
bar = 2
`,
{
code: unIndent`
var foo = 1,
bar =
2
`,
options: [2, { VariableDeclarator: 1 }]
},
{
code: unIndent`
var foo = 1,
bar
= 2
`,
options: [2, { VariableDeclarator: 1 }]
},
{
code: unIndent`
var foo
= 1,
bar
= 2
`,
options: [2, { VariableDeclarator: 1 }]
},
{
code: unIndent`
var foo
=
1,
bar
=
2
`,
options: [2, { VariableDeclarator: 1 }]
},
{
code: unIndent`
var foo
= (1),
bar
= (2)
`,
options: [2, { VariableDeclarator: 1 }]
},
{
code: unIndent`
let foo = 'foo',
bar = bar;
const a = 'a',
b = 'b';
`,
options: [2, { VariableDeclarator: "first" }]
},
{
code: unIndent`
let foo = 'foo',
bar = bar // <-- no semicolon here
const a = 'a',
b = 'b' // <-- no semicolon here
`,
options: [2, { VariableDeclarator: "first" }]
},
{
code: unIndent`
var foo = 1,
bar = 2,
baz = 3
;
`,
options: [2, { VariableDeclarator: { var: 2 } }]
},
{
code: unIndent`
var foo = 1,
bar = 2,
baz = 3
;
`,
options: [2, { VariableDeclarator: { var: 2 } }]
},
{
code: unIndent`
var foo = 'foo',
bar = bar;
`,
options: [2, { VariableDeclarator: { var: "first" } }]
},
{
code: unIndent`
var foo = 'foo',
bar = 'bar' // <-- no semicolon here
`,
options: [2, { VariableDeclarator: { var: "first" } }]
},
{
code: unIndent`
let foo = 1,
bar = 2,
baz
`,
options: [2, { VariableDeclarator: "first" }]
},
{
code: unIndent`
let
foo
`,
options: [4, { VariableDeclarator: "first" }]
},
{
code: unIndent`
let foo = 1,
bar =
2
`,
options: [2, { VariableDeclarator: "first" }]
},
{
code: unIndent`
var abc =
{
a: 1,
b: 2
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
var a = new abc({
a: 1,
b: 2
}),
b = 2;
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var a = 2,
c = {
a: 1,
b: 2
},
b = 2;
`,
options: [2, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var x = 2,
y = {
a: 1,
b: 2
},
b = 2;
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
var e = {
a: 1,
b: 2
},
b = 2;
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
var a = {
a: 1,
b: 2
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
function test() {
if (true ||
false){
console.log(val);
}
}
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
unIndent`
var foo = bar ||
!(
baz
);
`,
unIndent`
for (var foo = 1;
foo < 10;
foo++) {}
`,
unIndent`
for (
var foo = 1;
foo < 10;
foo++
) {}
`,
{
code: unIndent`
for (var val in obj)
if (true)
console.log(val);
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
if(true)
if (true)
if (true)
console.log(val);
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
function hi(){ var a = 1;
y++; x++;
}
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
for(;length > index; index++)if(NO_HOLES || index in self){
x++;
}
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
function test(){
switch(length){
case 1: return function(a){
return fn.call(that, a);
};
}
}
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
var geometry = 2,
rotate = 2;
`,
options: [2, { VariableDeclarator: 0 }]
},
{
code: unIndent`
var geometry,
rotate;
`,
options: [4, { VariableDeclarator: 1 }]
},
{
code: unIndent`
var geometry,
\trotate;
`,
options: ["tab", { VariableDeclarator: 1 }]
},
{
code: unIndent`
var geometry,
rotate;
`,
options: [2, { VariableDeclarator: 1 }]
},
{
code: unIndent`
var geometry,
rotate;
`,
options: [2, { VariableDeclarator: 2 }]
},
{
code: unIndent`
let geometry,
rotate;
`,
options: [2, { VariableDeclarator: 2 }]
},
{
code: unIndent`
const geometry = 2,
rotate = 3;
`,
options: [2, { VariableDeclarator: 2 }]
},
{
code: unIndent`
var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth,
height, rotate;
`,
options: [2, { SwitchCase: 1 }]
},
{
code: "var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth;",
options: [2, { SwitchCase: 1 }]
},
{
code: unIndent`
if (1 < 2){
//hi sd
}
`,
options: [2]
},
{
code: unIndent`
while (1 < 2){
//hi sd
}
`,
options: [2]
},
{
code: "while (1 < 2) console.log('hi');",
options: [2]
},
{
code: unIndent`
[a, boop,
c].forEach((index) => {
index;
});
`,
options: [4]
},
{
code: unIndent`
[a, b,
c].forEach(function(index){
return index;
});
`,
options: [4]
},
{
code: unIndent`
[a, b, c].forEach((index) => {
index;
});
`,
options: [4]
},
{
code: unIndent`
[a, b, c].forEach(function(index){
return index;
});
`,
options: [4]
},
{
code: unIndent`
(foo)
.bar([
baz
]);
`,
options: [4, { MemberExpression: 1 }]
},
{
code: unIndent`
switch (x) {
case "foo":
a();
break;
case "bar":
switch (y) {
case "1":
break;
case "2":
a = 6;
break;
}
case "test":
break;
}
`,
options: [4, { SwitchCase: 1 }]
},
{
code: unIndent`
switch (x) {
case "foo":
a();
break;
case "bar":
switch (y) {
case "1":
break;
case "2":
a = 6;
break;
}
case "test":
break;
}
`,
options: [4, { SwitchCase: 2 }]
},
unIndent`
switch (a) {
case "foo":
a();
break;
case "bar":
switch(x){
case '1':
break;
case '2':
a = 6;
break;
}
}
`,
unIndent`
switch (a) {
case "foo":
a();
break;
case "bar":
if(x){
a = 2;
}
else{
a = 6;
}
}
`,
unIndent`
switch (a) {
case "foo":
a();
break;
case "bar":
if(x){
a = 2;
}
else
a = 6;
}
`,
unIndent`
switch (a) {
case "foo":
a();
break;
case "bar":
a(); break;
case "baz":
a(); break;
}
`,
unIndent`
switch (0) {
}
`,
unIndent`
function foo() {
var a = "a";
switch(a) {
case "a":
return "A";
case "b":
return "B";
}
}
foo();
`,
{
code: unIndent`
switch(value){
case "1":
case "2":
a();
break;
default:
a();
break;
}
switch(value){
case "1":
a();
break;
case "2":
break;
default:
break;
}
`,
options: [4, { SwitchCase: 1 }]
},
unIndent`
var obj = {foo: 1, bar: 2};
with (obj) {
console.log(foo + bar);
}
`,
unIndent`
if (a) {
(1 + 2 + 3); // no error on this line
}
`,
"switch(value){ default: a(); break; }",
{
code: unIndent`
import {addons} from 'react/addons'
import React from 'react'
`,
options: [2],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
import {
foo,
bar,
baz
} from 'qux';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
var foo = 0, bar = 0; baz = 0;
export {
foo,
bar,
baz
} from 'qux';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
var a = 1,
b = 2,
c = 3;
`,
options: [4]
},
{
code: unIndent`
var a = 1
,b = 2
,c = 3;
`,
options: [4]
},
{
code: "while (1 < 2) console.log('hi')",
options: [2]
},
{
code: unIndent`
function salutation () {
switch (1) {
case 0: return console.log('hi')
case 1: return console.log('hey')
}
}
`,
options: [2, { SwitchCase: 1 }]
},
{
code: unIndent`
var items = [
{
foo: 'bar'
}
];
`,
options: [2, { VariableDeclarator: 2 }]
},
{
code: unIndent`
const a = 1,
b = 2;
const items1 = [
{
foo: 'bar'
}
];
const items2 = Items(
{
foo: 'bar'
}
);
`,
options: [2, { VariableDeclarator: 3 }]
},
{
code: unIndent`
const geometry = 2,
rotate = 3;
var a = 1,
b = 2;
let light = true,
shadow = false;
`,
options: [2, { VariableDeclarator: { const: 3, let: 2 } }]
},
{
code: unIndent`
const abc = 5,
c = 2,
xyz =
{
a: 1,
b: 2
};
let abc2 = 5,
c2 = 2,
xyz2 =
{
a: 1,
b: 2
};
var abc3 = 5,
c3 = 2,
xyz3 =
{
a: 1,
b: 2
};
`,
options: [2, { VariableDeclarator: { var: 2, const: 3 }, SwitchCase: 1 }]
},
{
code: unIndent`
module.exports = {
'Unit tests':
{
rootPath: './',
environment: 'node',
tests:
[
'test/test-*.js'
],
sources:
[
'*.js',
'test/**.js'
]
}
};
`,
options: [2]
},
{
code: unIndent`
foo =
bar;
`,
options: [2]
},
{
code: unIndent`
foo = (
bar
);
`,
options: [2]
},
{
code: unIndent`
var path = require('path')
, crypto = require('crypto')
;
`,
options: [2]
},
unIndent`
var a = 1
,b = 2
;
`,
{
code: unIndent`
export function create (some,
argument) {
return Object.create({
a: some,
b: argument
});
};
`,
options: [2, { FunctionDeclaration: { parameters: "first" } }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
export function create (id, xfilter, rawType,
width=defaultWidth, height=defaultHeight,
footerHeight=defaultFooterHeight,
padding=defaultPadding) {
// ... function body, indented two spaces
}
`,
options: [2, { FunctionDeclaration: { parameters: "first" } }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
var obj = {
foo: function () {
return new p()
.then(function (ok) {
return ok;
}, function () {
// ignore things
});
}
};
`,
options: [2]
},
{
code: unIndent`
a.b()
.c(function(){
var a;
}).d.e;
`,
options: [2]
},
{
code: unIndent`
const YO = 'bah',
TE = 'mah'
var res,
a = 5,
b = 4
`,
options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }]
},
{
code: unIndent`
const YO = 'bah',
TE = 'mah'
var res,
a = 5,
b = 4
if (YO) console.log(TE)
`,
options: [2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }]
},
{
code: unIndent`
var foo = 'foo',
bar = 'bar',
baz = function() {
}
function hello () {
}
`,
options: [2]
},
{
code: unIndent`
var obj = {
send: function () {
return P.resolve({
type: 'POST'
})
.then(function () {
return true;
}, function () {
return false;
});
}
};
`,
options: [2]
},
{
code: unIndent`
var obj = {
send: function () {
return P.resolve({
type: 'POST'
})
.then(function () {
return true;
}, function () {
return false;
});
}
};
`,
options: [2, { MemberExpression: 0 }]
},
unIndent`
const someOtherFunction = argument => {
console.log(argument);
},
someOtherValue = 'someOtherValue';
`,
{
code: unIndent`
[
'a',
'b'
].sort().should.deepEqual([
'x',
'y'
]);
`,
options: [2]
},
{
code: unIndent`
var a = 1,
B = class {
constructor(){}
a(){}
get b(){}
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
var a = 1,
B =
class {
constructor(){}
a(){}
get b(){}
},
c = 3;
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }]
},
{
code: unIndent`
class A{
constructor(){}
a(){}
get b(){}
}
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var A = class {
constructor(){}
a(){}
get b(){}
}
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }]
},
{
code: unIndent`
var a = {
some: 1
, name: 2
};
`,
options: [2]
},
{
code: unIndent`
a.c = {
aa: function() {
'test1';
return 'aa';
}
, bb: function() {
return this.bb();
}
};
`,
options: [4]
},
{
code: unIndent`
var a =
{
actions:
[
{
name: 'compile'
}
]
};
`,
options: [4, { VariableDeclarator: 0, SwitchCase: 1 }]
},
{
code: unIndent`
var a =
[
{
name: 'compile'
}
];
`,
options: [4, { VariableDeclarator: 0, SwitchCase: 1 }]
},
unIndent`
[[
], function(
foo
) {}
]
`,
unIndent`
define([
'foo'
], function(
bar
) {
baz;
}
)
`,
{
code: unIndent`
const func = function (opts) {
return Promise.resolve()
.then(() => {
[
'ONE', 'TWO'
].forEach(command => { doSomething(); });
});
};
`,
options: [4, { MemberExpression: 0 }]
},
{
code: unIndent`
const func = function (opts) {
return Promise.resolve()
.then(() => {
[
'ONE', 'TWO'
].forEach(command => { doSomething(); });
});
};
`,
options: [4]
},
{
code: unIndent`
var haveFun = function () {
SillyFunction(
{
value: true,
},
{
_id: true,
}
);
};
`,
options: [4]
},
{
code: unIndent`
var haveFun = function () {
new SillyFunction(
{
value: true,
},
{
_id: true,
}
);
};
`,
options: [4]
},
{
code: unIndent`
let object1 = {
doThing() {
return _.chain([])
.map(v => (
{
value: true,
}
))
.value();
}
};
`,
options: [2]
},
{
code: unIndent`
var foo = {
bar: 1,
baz: {
qux: 2
}
},
bar = 1;
`,
options: [2]
},
{
code: unIndent`
class Foo
extends Bar {
baz() {}
}
`,
options: [2]
},
{
code: unIndent`
class Foo extends
Bar {
baz() {}
}
`,
options: [2]
},
{
code: unIndent`
class Foo extends
(
Bar
) {
baz() {}
}
`,
options: [2]
},
{
code: unIndent`
fs.readdirSync(path.join(__dirname, '../rules')).forEach(name => {
files[name] = foo;
});
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
options: [4, { outerIIFEBody: 2 }]
},
{
code: unIndent`
(function(x, y){
function foo(x) {
return x + 1;
}
})(1, 2);
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
}());
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
!function(){
function foo(x) {
return x + 1;
}
}();
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
!function(){
\t\t\tfunction foo(x) {
\t\t\t\treturn x + 1;
\t\t\t}
}();
`,
options: ["tab", { outerIIFEBody: 3 }]
},
{
code: unIndent`
var out = function(){
function fooVar(x) {
return x + 1;
}
};
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
var ns = function(){
function fooVar(x) {
return x + 1;
}
}();
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
ns = function(){
function fooVar(x) {
return x + 1;
}
}();
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
var ns = (function(){
function fooVar(x) {
return x + 1;
}
}(x));
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
var ns = (function(){
function fooVar(x) {
return x + 1;
}
}(x));
`,
options: [4, { outerIIFEBody: 2 }]
},
{
code: unIndent`
var obj = {
foo: function() {
return true;
}
};
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
while (
function() {
return true;
}()) {
x = x + 1;
};
`,
options: [2, { outerIIFEBody: 20 }]
},
{
code: unIndent`
(() => {
function foo(x) {
return x + 1;
}
})();
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
function foo() {
}
`,
options: ["tab", { outerIIFEBody: 0 }]
},
{
code: unIndent`
;(() => {
function foo(x) {
return x + 1;
}
})();
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
if(data) {
console.log('hi');
}
`,
options: [2, { outerIIFEBody: 0 }]
},
{
code: unIndent`
(function(x) {
return x + 1;
})();
`,
options: [4, { outerIIFEBody: "off" }]
},
{
code: unIndent`
(function(x) {
return x + 1;
})();
`,
options: [4, { outerIIFEBody: "off" }]
},
{
code: unIndent`
;(() => {
function x(y) {
return y + 1;
}
})();
`,
options: [4, { outerIIFEBody: "off" }]
},
{
code: unIndent`
;(() => {
function x(y) {
return y + 1;
}
})();
`,
options: [4, { outerIIFEBody: "off" }]
},
{
code: unIndent`
function foo() {
}
`,
options: [4, { outerIIFEBody: "off" }]
},
{
code: "Buffer.length",
options: [4, { MemberExpression: 1 }]
},
{
code: unIndent`
Buffer
.indexOf('a')
.toString()
`,
options: [4, { MemberExpression: 1 }]
},
{
code: unIndent`
Buffer.
length
`,
options: [4, { MemberExpression: 1 }]
},
{
code: unIndent`
Buffer
.foo
.bar
`,
options: [4, { MemberExpression: 1 }]
},
{
code: unIndent`
Buffer
\t.foo
\t.bar
`,
options: ["tab", { MemberExpression: 1 }]
},
{
code: unIndent`
Buffer
.foo
.bar
`,
options: [2, { MemberExpression: 2 }]
},
unIndent`
(
foo
.bar
)
`,
unIndent`
(
(
foo
.bar
)
)
`,
unIndent`
(
foo
)
.bar
`,
unIndent`
(
(
foo
)
.bar
)
`,
unIndent`
(
(
foo
)
[
(
bar
)
]
)
`,
unIndent`
(
foo[bar]
)
.baz
`,
unIndent`
(
(foo.bar)
)
.baz
`,
{
code: unIndent`
MemberExpression
.can
.be
.turned
.off();
`,
options: [4, { MemberExpression: "off" }]
},
{
code: unIndent`
foo = bar.baz()
.bip();
`,
options: [4, { MemberExpression: 1 }]
},
unIndent`
function foo() {
new
.target
}
`,
unIndent`
function foo() {
new.
target
}
`,
{
code: unIndent`
if (foo) {
bar();
} else if (baz) {
foobar();
} else if (qux) {
qux();
}
`,
options: [2]
},
{
code: unIndent`
function foo(aaa,
bbb, ccc, ddd) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: 1, body: 2 } }]
},
{
code: unIndent`
function foo(aaa, bbb,
ccc, ddd) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: 3, body: 1 } }]
},
{
code: unIndent`
function foo(aaa,
bbb,
ccc) {
bar();
}
`,
options: [4, { FunctionDeclaration: { parameters: 1, body: 3 } }]
},
{
code: unIndent`
function foo(aaa,
bbb, ccc,
ddd, eee, fff) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: "first", body: 1 } }]
},
{
code: unIndent`
function foo(aaa, bbb)
{
bar();
}
`,
options: [2, { FunctionDeclaration: { body: 3 } }]
},
{
code: unIndent`
function foo(
aaa,
bbb) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: "first", body: 2 } }]
},
{
code: unIndent`
var foo = function(aaa,
bbb,
ccc,
ddd) {
bar();
}
`,
options: [2, { FunctionExpression: { parameters: 2, body: 0 } }]
},
{
code: unIndent`
var foo = function(aaa,
bbb,
ccc) {
bar();
}
`,
options: [2, { FunctionExpression: { parameters: 1, body: 10 } }]
},
{
code: unIndent`
var foo = function(aaa,
bbb, ccc, ddd,
eee, fff) {
bar();
}
`,
options: [4, { FunctionExpression: { parameters: "first", body: 1 } }]
},
{
code: unIndent`
var foo = function(
aaa, bbb, ccc,
ddd, eee) {
bar();
}
`,
options: [2, { FunctionExpression: { parameters: "first", body: 3 } }]
},
{
code: unIndent`
foo.bar(
baz, qux, function() {
qux;
}
);
`,
options: [2, { FunctionExpression: { body: 3 }, CallExpression: { arguments: 3 } }]
},
{
code: unIndent`
function foo() {
bar();
\tbaz();
\t \t\t\t \t\t\t \t \tqux();
}
`,
options: [2]
},
{
code: unIndent`
function foo() {
function bar() {
baz();
}
}
`,
options: [2, { FunctionDeclaration: { body: 1 } }]
},
{
code: unIndent`
function foo() {
bar();
\t\t}
`,
options: [2]
},
{
code: unIndent`
function foo() {
function bar(baz,
qux) {
foobar();
}
}
`,
options: [2, { FunctionDeclaration: { body: 1, parameters: 2 } }]
},
{
code: unIndent`
((
foo
))
`,
options: [4]
},
// ternary expressions (https://github.com/eslint/eslint/issues/7420)
{
code: unIndent`
foo
? bar
: baz
`,
options: [2]
},
{
code: unIndent`
foo = (bar ?
baz :
qux
);
`,
options: [2]
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [2]
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [2, { offsetTernaryExpressions: false }]
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [2, { offsetTernaryExpressions: true }]
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [4, { offsetTernaryExpressions: true }]
},
{
code: unIndent`
condition1
? condition2
? Promise.resolve(1)
: Promise.resolve(2)
: Promise.resolve(3)
`,
options: [2, { offsetTernaryExpressions: true }]
},
{
code: unIndent`
condition1
? Promise.resolve(1)
: condition2
? Promise.resolve(2)
: Promise.resolve(3)
`,
options: [2, { offsetTernaryExpressions: true }]
},
{
code: unIndent`
condition
\t? () => {
\t\t\treturn true
\t\t}
\t: condition2
\t\t? () => {
\t\t\t\treturn true
\t\t\t}
\t\t: () => {
\t\t\t\treturn false
\t\t\t}
`,
options: ["tab", { offsetTernaryExpressions: true }]
},
unIndent`
[
foo ?
bar :
baz,
qux
];
`,
{
/*
* Checking comments:
* https://github.com/eslint/eslint/issues/3845, https://github.com/eslint/eslint/issues/6571
*/
code: unIndent`
foo();
// Line
/* multiline
Line */
bar();
// trailing comment
`,
options: [2]
},
{
code: unIndent`
switch (foo) {
case bar:
baz();
// call the baz function
}
`,
options: [2, { SwitchCase: 1 }]
},
{
code: unIndent`
switch (foo) {
case bar:
baz();
// no default
}
`,
options: [2, { SwitchCase: 1 }]
},
unIndent`
[
// no elements
]
`,
{
/*
* Destructuring assignments:
* https://github.com/eslint/eslint/issues/6813
*/
code: unIndent`
var {
foo,
bar,
baz: qux,
foobar: baz = foobar
} = qux;
`,
options: [2]
},
{
code: unIndent`
var [
foo,
bar,
baz,
foobar = baz
] = qux;
`,
options: [2]
},
{
code: unIndent`
const {
a
}
=
{
a: 1
}
`,
options: [2]
},
{
code: unIndent`
const {
a
} = {
a: 1
}
`,
options: [2]
},
{
code: unIndent`
const
{
a
} = {
a: 1
};
`,
options: [2]
},
{
code: unIndent`
const
foo = {
bar: 1
}
`,
options: [2]
},
{
code: unIndent`
const [
a
] = [
1
]
`,
options: [2]
},
{
// https://github.com/eslint/eslint/issues/7233
code: unIndent`
var folder = filePath
.foo()
.bar;
`,
options: [2, { MemberExpression: 2 }]
},
{
code: unIndent`
for (const foo of bar)
baz();
`,
options: [2]
},
{
code: unIndent`
var x = () =>
5;
`,
options: [2]
},
unIndent`
(
foo
)(
bar
)
`,
unIndent`
(() =>
foo
)(
bar
)
`,
unIndent`
(() => {
foo();
})(
bar
)
`,
{
// Don't lint the indentation of the first token after a :
code: unIndent`
({code:
"foo.bar();"})
`,
options: [2]
},
{
// Don't lint the indentation of the first token after a :
code: unIndent`
({code:
"foo.bar();"})
`,
options: [2]
},
unIndent`
({
foo:
bar
})
`,
unIndent`
({
[foo]:
bar
})
`,
{
// Comments in switch cases
code: unIndent`
switch (foo) {
// comment
case study:
// comment
bar();
case closed:
/* multiline comment
*/
}
`,
options: [2, { SwitchCase: 1 }]
},
{
// Comments in switch cases
code: unIndent`
switch (foo) {
// comment
case study:
// the comment can also be here
case closed:
}
`,
options: [2, { SwitchCase: 1 }]
},
{
// BinaryExpressions with parens
code: unIndent`
foo && (
bar
)
`,
options: [4]
},
{
// BinaryExpressions with parens
code: unIndent`
foo && ((
bar
))
`,
options: [4]
},
{
code: unIndent`
foo &&
(
bar
)
`,
options: [4]
},
unIndent`
foo &&
!bar(
)
`,
unIndent`
foo &&
![].map(() => {
bar();
})
`,
{
code: unIndent`
foo =
bar;
`,
options: [4]
},
{
code: unIndent`
function foo() {
var bar = function(baz,
qux) {
foobar();
};
}
`,
options: [2, { FunctionExpression: { parameters: 3 } }]
},
unIndent`
function foo() {
return (bar === 1 || bar === 2 &&
(/Function/.test(grandparent.type))) &&
directives(parent).indexOf(node) >= 0;
}
`,
{
code: unIndent`
function foo() {
return (foo === bar || (
baz === qux && (
foo === foo ||
bar === bar ||
baz === baz
)
))
}
`,
options: [4]
},
unIndent`
if (
foo === 1 ||
bar === 1 ||
// comment
(baz === 1 && qux === 1)
) {}
`,
{
code: unIndent`
foo =
(bar + baz);
`,
options: [2]
},
{
code: unIndent`
function foo() {
return (bar === 1 || bar === 2) &&
(z === 3 || z === 4);
}
`,
options: [2]
},
{
code: unIndent`
/* comment */ if (foo) {
bar();
}
`,
options: [2]
},
{
// Comments at the end of if blocks that have `else` blocks can either refer to the lines above or below them
code: unIndent`
if (foo) {
bar();
// Otherwise, if foo is false, do baz.
// baz is very important.
} else {
baz();
}
`,
options: [2]
},
{
code: unIndent`
function foo() {
return ((bar === 1 || bar === 2) &&
(z === 3 || z === 4));
}
`,
options: [2]
},
{
code: unIndent`
foo(
bar,
baz,
qux
);
`,
options: [2, { CallExpression: { arguments: 1 } }]
},
{
code: unIndent`
foo(
\tbar,
\tbaz,
\tqux
);
`,
options: ["tab", { CallExpression: { arguments: 1 } }]
},
{
code: unIndent`
foo(bar,
baz,
qux);
`,
options: [4, { CallExpression: { arguments: 2 } }]
},
{
code: unIndent`
foo(
bar,
baz,
qux
);
`,
options: [2, { CallExpression: { arguments: 0 } }]
},
{
code: unIndent`
foo(bar,
baz,
qux
);
`,
options: [2, { CallExpression: { arguments: "first" } }]
},
{
code: unIndent`
foo(bar, baz,
qux, barbaz,
barqux, bazqux);
`,
options: [2, { CallExpression: { arguments: "first" } }]
},
{
code: unIndent`
foo(bar,
1 + 2,
!baz,
new Car('!')
);
`,
options: [2, { CallExpression: { arguments: 4 } }]
},
unIndent`
foo(
(bar)
);
`,
{
code: unIndent`
foo(
(bar)
);
`,
options: [4, { CallExpression: { arguments: 1 } }]
},
// https://github.com/eslint/eslint/issues/7484
{
code: unIndent`
var foo = function() {
return bar(
[{
}].concat(baz)
);
};
`,
options: [2]
},
// https://github.com/eslint/eslint/issues/7573
{
code: unIndent`
return (
foo
);
`,
parserOptions: { ecmaFeatures: { globalReturn: true } }
},
{
code: unIndent`
return (
foo
)
`,
parserOptions: { ecmaFeatures: { globalReturn: true } }
},
unIndent`
var foo = [
bar,
baz
]
`,
unIndent`
var foo = [bar,
baz,
qux
]
`,
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
options: [2, { ArrayExpression: 0 }]
},
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
options: [2, { ArrayExpression: 8 }]
},
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
options: [2, { ArrayExpression: "first" }]
},
{
code: unIndent`
var foo = [bar,
baz, qux
]
`,
options: [2, { ArrayExpression: "first" }]
},
{
code: unIndent`
var foo = [
{ bar: 1,
baz: 2 },
{ bar: 3,
baz: 4 }
]
`,
options: [4, { ArrayExpression: 2, ObjectExpression: "first" }]
},
{
code: unIndent`
var foo = {
bar: 1,
baz: 2
};
`,
options: [2, { ObjectExpression: 0 }]
},
{
code: unIndent`
var foo = { foo: 1, bar: 2,
baz: 3 }
`,
options: [2, { ObjectExpression: "first" }]
},
{
code: unIndent`
var foo = [
{
foo: 1
}
]
`,
options: [4, { ArrayExpression: 2 }]
},
{
code: unIndent`
function foo() {
[
foo
]
}
`,
options: [2, { ArrayExpression: 4 }]
},
{
code: "[\n]",
options: [2, { ArrayExpression: "first" }]
},
{
code: "[\n]",
options: [2, { ArrayExpression: 1 }]
},
{
code: "{\n}",
options: [2, { ObjectExpression: "first" }]
},
{
code: "{\n}",
options: [2, { ObjectExpression: 1 }]
},
{
code: unIndent`
var foo = [
[
1
]
]
`,
options: [2, { ArrayExpression: "first" }]
},
{
code: unIndent`
var foo = [ 1,
[
2
]
];
`,
options: [2, { ArrayExpression: "first" }]
},
{
code: unIndent`
var foo = bar(1,
[ 2,
3
]
);
`,
options: [4, { ArrayExpression: "first", CallExpression: { arguments: "first" } }]
},
{
code: unIndent`
var foo =
[
]()
`,
options: [4, { CallExpression: { arguments: "first" }, ArrayExpression: "first" }]
},
// https://github.com/eslint/eslint/issues/7732
{
code: unIndent`
const lambda = foo => {
Object.assign({},
filterName,
{
display
}
);
}
`,
options: [2, { ObjectExpression: 1 }]
},
{
code: unIndent`
const lambda = foo => {
Object.assign({},
filterName,
{
display
}
);
}
`,
options: [2, { ObjectExpression: "first" }]
},
// https://github.com/eslint/eslint/issues/7733
{
code: unIndent`
var foo = function() {
\twindow.foo('foo',
\t\t{
\t\t\tfoo: 'bar',
\t\t\tbar: {
\t\t\t\tfoo: 'bar'
\t\t\t}
\t\t}
\t);
}
`,
options: ["tab"]
},
{
code: unIndent`
echo = spawn('cmd.exe',
['foo', 'bar',
'baz']);
`,
options: [2, { ArrayExpression: "first", CallExpression: { arguments: "first" } }]
},
{
code: unIndent`
if (foo)
bar();
// Otherwise, if foo is false, do baz.
// baz is very important.
else {
baz();
}
`,
options: [2]
},
{
code: unIndent`
if (
foo && bar ||
baz && qux // This line is ignored because BinaryExpressions are not checked.
) {
qux();
}
`,
options: [4]
},
unIndent`
[
] || [
]
`,
unIndent`
(
[
] || [
]
)
`,
unIndent`
1
+ (
1
)
`,
unIndent`
(
foo && (
bar ||
baz
)
)
`,
unIndent`
foo
|| (
bar
)
`,
unIndent`
foo
|| (
bar
)
`,
{
code: unIndent`
var foo =
1;
`,
options: [4, { VariableDeclarator: 2 }]
},
{
code: unIndent`
var foo = 1,
bar =
2;
`,
options: [4]
},
{
code: unIndent`
switch (foo) {
case bar:
{
baz();
}
}
`,
options: [2, { SwitchCase: 1 }]
},
// Template curlies
{
code: unIndent`
\`foo\${
bar}\`
`,
options: [2]
},
{
code: unIndent`
\`foo\${
\`bar\${
baz}\`}\`
`,
options: [2]
},
{
code: unIndent`
\`foo\${
\`bar\${
baz
}\`
}\`
`,
options: [2]
},
{
code: unIndent`
\`foo\${
(
bar
)
}\`
`,
options: [2]
},
unIndent`
foo(\`
bar
\`, {
baz: 1
});
`,
unIndent`
function foo() {
\`foo\${bar}baz\${
qux}foo\${
bar}baz\`
}
`,
unIndent`
JSON
.stringify(
{
ok: true
}
);
`,
// Don't check AssignmentExpression assignments
unIndent`
foo =
bar =
baz;
`,
unIndent`
foo =
bar =
baz;
`,
unIndent`
function foo() {
const template = \`this indentation is not checked
because it's part of a template literal.\`;
}
`,
unIndent`
function foo() {
const template = \`the indentation of a \${
node.type
} node is checked.\`;
}
`,
{
// https://github.com/eslint/eslint/issues/7320
code: unIndent`
JSON
.stringify(
{
test: 'test'
}
);
`,
options: [4, { CallExpression: { arguments: 1 } }]
},
unIndent`
[
foo,
// comment
// another comment
bar
]
`,
unIndent`
if (foo) {
/* comment */ bar();
}
`,
unIndent`
function foo() {
return (
1
);
}
`,
unIndent`
function foo() {
return (
1
)
}
`,
unIndent`
if (
foo &&
!(
bar
)
) {}
`,
{
// https://github.com/eslint/eslint/issues/6007
code: unIndent`
var abc = [
(
''
),
def,
]
`,
options: [2]
},
{
code: unIndent`
var abc = [
(
''
),
(
'bar'
)
]
`,
options: [2]
},
unIndent`
function f() {
return asyncCall()
.then(
'some string',
[
1,
2,
3
]
);
}
`,
{
// https://github.com/eslint/eslint/issues/6670
code: unIndent`
function f() {
return asyncCall()
.then(
'some string',
[
1,
2,
3
]
);
}
`,
options: [4, { MemberExpression: 1 }]
},
// https://github.com/eslint/eslint/issues/7242
unIndent`
var x = [
[1],
[2]
]
`,
unIndent`
var y = [
{a: 1},
{b: 2}
]
`,
unIndent`
foo(
)
`,
{
// https://github.com/eslint/eslint/issues/7616
code: unIndent`
foo(
bar,
{
baz: 1
}
)
`,
options: [4, { CallExpression: { arguments: "first" } }]
},
"new Foo",
"new (Foo)",
unIndent`
if (Foo) {
new Foo
}
`,
{
code: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
}
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo ?
bar :
baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo ?
bar
: baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo
? bar :
baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo
? bar
: baz
? qux
: foobar
? boop
: beep
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo ?
bar :
baz ?
qux :
foobar ?
boop :
beep
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
var a =
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
var a = foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
var a =
foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
a =
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
a = foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
a =
foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo(
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
)
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function wrap() {
return (
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
)
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function wrap() {
return foo
? bar
: baz
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function wrap() {
return (
foo
? bar
: baz
)
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo(
foo
? bar
: baz
)
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo(foo
? bar
: baz
)
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo
? bar
: baz
? qux
: foobar
? boop
: beep
`,
options: [4, { flatTernaryExpressions: false }]
},
{
code: unIndent`
foo ?
bar :
baz ?
qux :
foobar ?
boop :
beep
`,
options: [4, { flatTernaryExpressions: false }]
},
{
code: "[,]",
options: [2, { ArrayExpression: "first" }]
},
{
code: "[,]",
options: [2, { ArrayExpression: "off" }]
},
{
code: unIndent`
[
,
foo
]
`,
options: [4, { ArrayExpression: "first" }]
},
{
code: "[sparse, , array];",
options: [2, { ArrayExpression: "first" }]
},
{
code: unIndent`
foo.bar('baz', function(err) {
qux;
});
`,
options: [2, { CallExpression: { arguments: "first" } }]
},
{
code: unIndent`
foo.bar(function() {
cookies;
}).baz(function() {
cookies;
});
`,
options: [2, { MemberExpression: 1 }]
},
{
code: unIndent`
foo.bar().baz(function() {
cookies;
}).qux(function() {
cookies;
});
`,
options: [2, { MemberExpression: 1 }]
},
{
code: unIndent`
(
{
foo: 1,
baz: 2
}
);
`,
options: [2, { ObjectExpression: "first" }]
},
{
code: unIndent`
foo(() => {
bar;
}, () => {
baz;
})
`,
options: [4, { CallExpression: { arguments: "first" } }]
},
{
code: unIndent`
[ foo,
bar ].forEach(function() {
baz;
})
`,
options: [2, { ArrayExpression: "first", MemberExpression: 1 }]
},
unIndent`
foo = bar[
baz
];
`,
{
code: unIndent`
foo[
bar
];
`,
options: [4, { MemberExpression: 1 }]
},
{
code: unIndent`
foo[
(
bar
)
];
`,
options: [4, { MemberExpression: 1 }]
},
unIndent`
if (foo)
bar;
else if (baz)
qux;
`,
unIndent`
if (foo) bar()
; [1, 2, 3].map(baz)
`,
unIndent`
if (foo)
;
`,
"x => {}",
{
code: unIndent`
import {foo}
from 'bar';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: "import 'foo'",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
import { foo,
bar,
baz,
} from 'qux';
`,
options: [4, { ImportDeclaration: 1 }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
import {
foo,
bar,
baz,
} from 'qux';
`,
options: [4, { ImportDeclaration: 1 }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
import { apple as a,
banana as b } from 'fruits';
import { cat } from 'animals';
`,
options: [4, { ImportDeclaration: "first" }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
import { declaration,
can,
be,
turned } from 'off';
`,
options: [4, { ImportDeclaration: "off" }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
// https://github.com/eslint/eslint/issues/8455
unIndent`
(
a
) => b => {
c
}
`,
unIndent`
(
a
) => b => c => d => {
e
}
`,
unIndent`
(
a
) =>
(
b
) => {
c
}
`,
unIndent`
if (
foo
) bar(
baz
);
`,
unIndent`
if (foo)
{
bar();
}
`,
unIndent`
function foo(bar)
{
baz();
}
`,
unIndent`
() =>
({})
`,
unIndent`
() =>
(({}))
`,
unIndent`
(
() =>
({})
)
`,
unIndent`
var x = function foop(bar)
{
baz();
}
`,
unIndent`
var x = (bar) =>
{
baz();
}
`,
unIndent`
class Foo
{
constructor()
{
foo();
}
bar()
{
baz();
}
}
`,
unIndent`
class Foo
extends Bar
{
constructor()
{
foo();
}
bar()
{
baz();
}
}
`,
unIndent`
(
class Foo
{
constructor()
{
foo();
}
bar()
{
baz();
}
}
)
`,
{
code: unIndent`
switch (foo)
{
case 1:
bar();
}
`,
options: [4, { SwitchCase: 1 }]
},
unIndent`
foo
.bar(function() {
baz
})
`,
{
code: unIndent`
foo
.bar(function() {
baz
})
`,
options: [4, { MemberExpression: 2 }]
},
unIndent`
foo
[bar](function() {
baz
})
`,
unIndent`
foo.
bar.
baz
`,
{
code: unIndent`
foo
.bar(function() {
baz
})
`,
options: [4, { MemberExpression: "off" }]
},
{
code: unIndent`
foo
.bar(function() {
baz
})
`,
options: [4, { MemberExpression: "off" }]
},
{
code: unIndent`
foo
[bar](function() {
baz
})
`,
options: [4, { MemberExpression: "off" }]
},
{
code: unIndent`
foo.
bar.
baz
`,
options: [4, { MemberExpression: "off" }]
},
{
code: unIndent`
foo = bar(
).baz(
)
`,
options: [4, { MemberExpression: "off" }]
},
{
code: unIndent`
foo[
bar ? baz :
qux
]
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
function foo() {
return foo ? bar :
baz
}
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
throw foo ? bar :
baz
`,
options: [4, { flatTernaryExpressions: true }]
},
{
code: unIndent`
foo(
bar
) ? baz :
qux
`,
options: [4, { flatTernaryExpressions: true }]
},
unIndent`
foo
[
bar
]
.baz(function() {
quz();
})
`,
unIndent`
[
foo
][
"map"](function() {
qux();
})
`,
unIndent`
(
a.b(function() {
c;
})
)
`,
unIndent`
(
foo
).bar(function() {
baz();
})
`,
unIndent`
new Foo(
bar
.baz
.qux
)
`,
unIndent`
const foo = a.b(),
longName =
(baz(
'bar',
'bar'
));
`,
unIndent`
const foo = a.b(),
longName =
(baz(
'bar',
'bar'
));
`,
unIndent`
const foo = a.b(),
longName =
baz(
'bar',
'bar'
);
`,
unIndent`
const foo = a.b(),
longName =
baz(
'bar',
'bar'
);
`,
unIndent`
const foo = a.b(),
longName
= baz(
'bar',
'bar'
);
`,
unIndent`
const foo = a.b(),
longName
= baz(
'bar',
'bar'
);
`,
unIndent`
const foo = a.b(),
longName =
('fff');
`,
unIndent`
const foo = a.b(),
longName =
('fff');
`,
unIndent`
const foo = a.b(),
longName
= ('fff');
`,
unIndent`
const foo = a.b(),
longName
= ('fff');
`,
unIndent`
const foo = a.b(),
longName =
(
'fff'
);
`,
unIndent`
const foo = a.b(),
longName =
(
'fff'
);
`,
unIndent`
const foo = a.b(),
longName
=(
'fff'
);
`,
unIndent`
const foo = a.b(),
longName
=(
'fff'
);
`,
//----------------------------------------------------------------------
// Ignore Unknown Nodes
//----------------------------------------------------------------------
{
code: unIndent`
interface Foo {
bar: string;
baz: number;
}
`,
parser: parser("unknown-nodes/interface")
},
{
code: unIndent`
namespace Foo {
const bar = 3,
baz = 2;
if (true) {
const bax = 3;
}
}
`,
parser: parser("unknown-nodes/namespace-valid")
},
{
code: unIndent`
abstract class Foo {
public bar() {
let aaa = 4,
boo;
if (true) {
boo = 3;
}
boo = 3 + 2;
}
}
`,
parser: parser("unknown-nodes/abstract-class-valid")
},
{
code: unIndent`
function foo() {
function bar() {
abstract class X {
public baz() {
if (true) {
qux();
}
}
}
}
}
`,
parser: parser("unknown-nodes/functions-with-abstract-class-valid")
},
{
code: unIndent`
namespace Unknown {
function foo() {
function bar() {
abstract class X {
public baz() {
if (true) {
qux();
}
}
}
}
}
}
`,
parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-valid")
},
{
code: unIndent`
type httpMethod = 'GET'
| 'POST'
| 'PUT';
`,
options: [2, { VariableDeclarator: 0 }],
parser: parser("unknown-nodes/variable-declarator-type-indent-two-spaces")
},
{
code: unIndent`
type httpMethod = 'GET'
| 'POST'
| 'PUT';
`,
options: [2, { VariableDeclarator: 1 }],
parser: parser("unknown-nodes/variable-declarator-type-no-indent")
},
unIndent`
foo(\`foo
\`, {
ok: true
},
{
ok: false
})
`,
unIndent`
foo(tag\`foo
\`, {
ok: true
},
{
ok: false
}
)
`,
// https://github.com/eslint/eslint/issues/8815
unIndent`
async function test() {
const {
foo,
bar,
} = await doSomethingAsync(
1,
2,
3,
);
}
`,
unIndent`
function* test() {
const {
foo,
bar,
} = yield doSomethingAsync(
1,
2,
3,
);
}
`,
unIndent`
({
a: b
} = +foo(
bar
));
`,
unIndent`
const {
foo,
bar,
} = typeof foo(
1,
2,
3,
);
`,
unIndent`
const {
foo,
bar,
} = +(
foo
);
`,
//----------------------------------------------------------------------
// JSX tests
// https://github.com/eslint/eslint/issues/8425
// Some of the following tests are adapted from the tests in eslint-plugin-react.
// License: https://github.com/yannickcr/eslint-plugin-react/blob/7ca9841f22d599f447a27ef5b2a97def9229d6c8/LICENSE
//----------------------------------------------------------------------
"<Foo a=\"b\" c=\"d\"/>;",
unIndent`
<Foo
a="b"
c="d"
/>;
`,
"var foo = <Bar a=\"b\" c=\"d\"/>;",
unIndent`
var foo = <Bar
a="b"
c="d"
/>;
`,
unIndent`
var foo = (<Bar
a="b"
c="d"
/>);
`,
unIndent`
var foo = (
<Bar
a="b"
c="d"
/>
);
`,
unIndent`
<
Foo
a="b"
c="d"
/>;
`,
unIndent`
<Foo
a="b"
c="d"/>;
`,
unIndent`
<
Foo
a="b"
c="d"/>;
`,
"<a href=\"foo\">bar</a>;",
unIndent`
<a href="foo">
bar
</a>;
`,
unIndent`
<a
href="foo"
>
bar
</a>;
`,
unIndent`
<a
href="foo">
bar
</a>;
`,
unIndent`
<
a
href="foo">
bar
</a>;
`,
unIndent`
<a
href="foo">
bar
</
a>;
`,
unIndent`
<a
href="foo">
bar
</a
>;
`,
unIndent`
var foo = <a href="bar">
baz
</a>;
`,
unIndent`
var foo = <a
href="bar"
>
baz
</a>;
`,
unIndent`
var foo = <a
href="bar">
baz
</a>;
`,
unIndent`
var foo = <
a
href="bar">
baz
</a>;
`,
unIndent`
var foo = <a
href="bar">
baz
</
a>;
`,
unIndent`
var foo = <a
href="bar">
baz
</a
>
`,
unIndent`
var foo = (<a
href="bar">
baz
</a>);
`,
unIndent`
var foo = (
<a href="bar">baz</a>
);
`,
unIndent`
var foo = (
<a href="bar">
baz
</a>
);
`,
unIndent`
var foo = (
<a
href="bar">
baz
</a>
);
`,
"var foo = <a href=\"bar\">baz</a>;",
unIndent`
<a>
{
}
</a>
`,
unIndent`
<a>
{
foo
}
</a>
`,
unIndent`
function foo() {
return (
<a>
{
b.forEach(() => {
// comment
a = c
.d()
.e();
})
}
</a>
);
}
`,
"<App></App>",
unIndent`
<App>
</App>
`,
{
code: unIndent`
<App>
<Foo />
</App>
`,
options: [2]
},
{
code: unIndent`
<App>
<Foo />
</App>
`,
options: [0]
},
{
code: unIndent`
<App>
\t<Foo />
</App>
`,
options: ["tab"]
},
{
code: unIndent`
function App() {
return <App>
<Foo />
</App>;
}
`,
options: [2]
},
{
code: unIndent`
function App() {
return (<App>
<Foo />
</App>);
}
`,
options: [2]
},
{
code: unIndent`
function App() {
return (
<App>
<Foo />
</App>
);
}
`,
options: [2]
},
{
code: unIndent`
it(
(
<div>
<span />
</div>
)
)
`,
options: [2]
},
{
code: unIndent`
it(
(<div>
<span />
<span />
<span />
</div>)
)
`,
options: [2]
},
{
code: unIndent`
(
<div>
<span />
</div>
)
`,
options: [2]
},
{
code: unIndent`
{
head.title &&
<h1>
{head.title}
</h1>
}
`,
options: [2]
},
{
code: unIndent`
{
head.title &&
<h1>
{head.title}
</h1>
}
`,
options: [2]
},
{
code: unIndent`
{
head.title && (
<h1>
{head.title}
</h1>)
}
`,
options: [2]
},
{
code: unIndent`
{
head.title && (
<h1>
{head.title}
</h1>
)
}
`,
options: [2]
},
{
code: unIndent`
[
<div />,
<div />
]
`,
options: [2]
},
unIndent`
<div>
{
[
<Foo />,
<Bar />
]
}
</div>
`,
unIndent`
<div>
{foo &&
[
<Foo />,
<Bar />
]
}
</div>
`,
unIndent`
<div>
bar <div>
bar
bar {foo}
bar </div>
</div>
`,
unIndent`
foo ?
<Foo /> :
<Bar />
`,
unIndent`
foo ?
<Foo />
: <Bar />
`,
unIndent`
foo ?
<Foo />
:
<Bar />
`,
unIndent`
<div>
{!foo ?
<Foo
onClick={this.onClick}
/>
:
<Bar
onClick={this.onClick}
/>
}
</div>
`,
{
code: unIndent`
<span>
{condition ?
<Thing
foo={\`bar\`}
/> :
<Thing/>
}
</span>
`,
options: [2]
},
{
code: unIndent`
<span>
{condition ?
<Thing
foo={"bar"}
/> :
<Thing/>
}
</span>
`,
options: [2]
},
{
code: unIndent`
function foo() {
<span>
{condition ?
<Thing
foo={bar}
/> :
<Thing/>
}
</span>
}
`,
options: [2]
},
unIndent`
<App foo
/>
`,
{
code: unIndent`
<App
foo
/>
`,
options: [2]
},
{
code: unIndent`
<App
foo
/>
`,
options: [0]
},
{
code: unIndent`
<App
\tfoo
/>
`,
options: ["tab"]
},
unIndent`
<App
foo
/>
`,
unIndent`
<App
foo
></App>
`,
{
code: unIndent`
<App
foo={function() {
console.log('bar');
}}
/>
`,
options: [2]
},
{
code: unIndent`
<App foo={function() {
console.log('bar');
}}
/>
`,
options: [2]
},
{
code: unIndent`
var x = function() {
return <App
foo={function() {
console.log('bar');
}}
/>
}
`,
options: [2]
},
{
code: unIndent`
var x = <App
foo={function() {
console.log('bar');
}}
/>
`,
options: [2]
},
{
code: unIndent`
<Provider
store
>
<App
foo={function() {
console.log('bar');
}}
/>
</Provider>
`,
options: [2]
},
{
code: unIndent`
<Provider
store
>
{baz && <App
foo={function() {
console.log('bar');
}}
/>}
</Provider>
`,
options: [2]
},
{
code: unIndent`
<App
\tfoo
/>
`,
options: ["tab"]
},
{
code: unIndent`
<App
\tfoo
></App>
`,
options: ["tab"]
},
{
code: unIndent`
<App foo={function() {
\tconsole.log('bar');
}}
/>
`,
options: ["tab"]
},
{
code: unIndent`
var x = <App
\tfoo={function() {
\t\tconsole.log('bar');
\t}}
/>
`,
options: ["tab"]
},
unIndent`
<App
foo />
`,
unIndent`
<div>
unrelated{
foo
}
</div>
`,
unIndent`
<div>unrelated{
foo
}
</div>
`,
unIndent`
<
foo
.bar
.baz
>
foo
</
foo.
bar.
baz
>
`,
unIndent`
<
input
type=
"number"
/>
`,
unIndent`
<
input
type=
{'number'}
/>
`,
unIndent`
<
input
type
="number"
/>
`,
unIndent`
foo ? (
bar
) : (
baz
)
`,
unIndent`
foo ? (
<div>
</div>
) : (
<span>
</span>
)
`,
unIndent`
<div>
{
/* foo */
}
</div>
`,
/*
* JSX Fragments
* https://github.com/eslint/eslint/issues/12208
*/
unIndent`
<>
<A />
</>
`,
unIndent`
<
>
<A />
</>
`,
unIndent`
<>
<A />
<
/>
`,
unIndent`
<>
<A />
</
>
`,
unIndent`
<
>
<A />
</
>
`,
unIndent`
<
>
<A />
<
/>
`,
unIndent`
< // Comment
>
<A />
</>
`,
unIndent`
<
// Comment
>
<A />
</>
`,
unIndent`
<
// Comment
>
<A />
</>
`,
unIndent`
<>
<A />
< // Comment
/>
`,
unIndent`
<>
<A />
<
// Comment
/>
`,
unIndent`
<>
<A />
<
// Comment
/>
`,
unIndent`
<>
<A />
</ // Comment
>
`,
unIndent`
<>
<A />
</
// Comment
>
`,
unIndent`
<>
<A />
</
// Comment
>
`,
unIndent`
< /* Comment */
>
<A />
</>
`,
unIndent`
<
/* Comment */
>
<A />
</>
`,
unIndent`
<
/* Comment */
>
<A />
</>
`,
unIndent`
<
/*
* Comment
*/
>
<A />
</>
`,
unIndent`
<
/*
* Comment
*/
>
<A />
</>
`,
unIndent`
<>
<A />
< /* Comment */
/>
`,
unIndent`
<>
<A />
<
/* Comment */ />
`,
unIndent`
<>
<A />
<
/* Comment */ />
`,
unIndent`
<>
<A />
<
/* Comment */
/>
`,
unIndent`
<>
<A />
<
/* Comment */
/>
`,
unIndent`
<>
<A />
</ /* Comment */
>
`,
unIndent`
<>
<A />
</
/* Comment */ >
`,
unIndent`
<>
<A />
</
/* Comment */ >
`,
unIndent`
<>
<A />
</
/* Comment */
>
`,
unIndent`
<>
<A />
</
/* Comment */
>
`,
// https://github.com/eslint/eslint/issues/8832
unIndent`
<div>
{
(
1
)
}
</div>
`,
unIndent`
function A() {
return (
<div>
{
b && (
<div>
</div>
)
}
</div>
);
}
`,
unIndent`
<div>foo
<div>bar</div>
</div>
`,
unIndent`
<small>Foo bar
<a>baz qux</a>.
</small>
`,
unIndent`
<div
{...props}
/>
`,
unIndent`
<div
{
...props
}
/>
`,
{
code: unIndent`
a(b
, c
)
`,
options: [2, { CallExpression: { arguments: "off" } }]
},
{
code: unIndent`
a(
new B({
c,
})
);
`,
options: [2, { CallExpression: { arguments: "off" } }]
},
{
code: unIndent`
foo
? bar
: baz
`,
options: [4, { ignoredNodes: ["ConditionalExpression"] }]
},
{
code: unIndent`
class Foo {
foo() {
bar();
}
}
`,
options: [4, { ignoredNodes: ["ClassBody"] }]
},
{
code: unIndent`
class Foo {
foo() {
bar();
}
}
`,
options: [4, { ignoredNodes: ["ClassBody", "BlockStatement"] }]
},
{
code: unIndent`
foo({
bar: 1
},
{
baz: 2
},
{
qux: 3
})
`,
options: [4, { ignoredNodes: ["CallExpression > ObjectExpression"] }]
},
{
code: unIndent`
foo
.bar
`,
options: [4, { ignoredNodes: ["MemberExpression"] }]
},
{
code: unIndent`
$(function() {
foo();
bar();
});
`,
options: [4, {
ignoredNodes: ["Program > ExpressionStatement > CallExpression[callee.name='$'] > FunctionExpression > BlockStatement"]
}]
},
{
code: unIndent`
<Foo
bar="1" />
`,
options: [4, { ignoredNodes: ["JSXOpeningElement"] }]
},
{
code: unIndent`
foo &&
<Bar
>
</Bar>
`,
options: [4, { ignoredNodes: ["JSXElement", "JSXOpeningElement"] }]
},
{
code: unIndent`
(function($) {
$(function() {
foo;
});
}())
`,
options: [4, { ignoredNodes: ["ExpressionStatement > CallExpression > FunctionExpression.callee > BlockStatement"] }]
},
{
code: unIndent`
const value = (
condition ?
valueIfTrue :
valueIfFalse
);
`,
options: [4, { ignoredNodes: ["ConditionalExpression"] }]
},
{
code: unIndent`
var a = 0, b = 0, c = 0;
export default foo(
a,
b, {
c
}
)
`,
options: [4, { ignoredNodes: ["ExportDefaultDeclaration > CallExpression > ObjectExpression"] }],
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: unIndent`
foobar = baz
? qux
: boop
`,
options: [4, { ignoredNodes: ["ConditionalExpression"] }]
},
{
code: unIndent`
\`
SELECT
\${
foo
} FROM THE_DATABASE
\`
`,
options: [4, { ignoredNodes: ["TemplateLiteral"] }]
},
{
code: unIndent`
<foo
prop='bar'
>
Text
</foo>
`,
options: [4, { ignoredNodes: ["JSXOpeningElement"] }]
},
{
code: unIndent`
{
\tvar x = 1,
\t y = 2;
}
`,
options: ["tab"]
},
{
code: unIndent`
var x = 1,
y = 2;
var z;
`,
options: ["tab", { ignoredNodes: ["VariableDeclarator"] }]
},
{
code: unIndent`
[
foo(),
bar
]
`,
options: ["tab", { ArrayExpression: "first", ignoredNodes: ["CallExpression"] }]
},
{
code: unIndent`
if (foo) {
doSomething();
// Intentionally unindented comment
doSomethingElse();
}
`,
options: [4, { ignoreComments: true }]
},
{
code: unIndent`
if (foo) {
doSomething();
/* Intentionally unindented comment */
doSomethingElse();
}
`,
options: [4, { ignoreComments: true }]
},
unIndent`
const obj = {
foo () {
return condition ? // comment
1 :
2
}
}
`,
//----------------------------------------------------------------------
// Comment alignment tests
//----------------------------------------------------------------------
unIndent`
if (foo) {
// Comment can align with code immediately above even if "incorrect" alignment
doSomething();
}
`,
unIndent`
if (foo) {
doSomething();
// Comment can align with code immediately below even if "incorrect" alignment
}
`,
unIndent`
if (foo) {
// Comment can be in correct alignment even if not aligned with code above/below
}
`,
unIndent`
if (foo) {
// Comment can be in correct alignment even if gaps between (and not aligned with) code above/below
}
`,
unIndent`
[{
foo
},
// Comment between nodes
{
bar
}];
`,
unIndent`
[{
foo
},
// Comment between nodes
{ // comment
bar
}];
`,
unIndent`
let foo
// comment
;(async () => {})()
`,
unIndent`
let foo
// comment
;(async () => {})()
`,
unIndent`
let foo
// comment
;(async () => {})()
`,
unIndent`
let foo
// comment
;(async () => {})()
`,
unIndent`
let foo
/* comment */;
(async () => {})()
`,
unIndent`
let foo
/* comment */;
(async () => {})()
`,
unIndent`
let foo
/* comment */;
(async () => {})()
`,
unIndent`
let foo
/* comment */;
(async () => {})()
`,
unIndent`
let foo
/* comment */;
(async () => {})()
`,
unIndent`
let foo
/* comment */;
(async () => {})()
`,
unIndent`
// comment
;(async () => {})()
`,
unIndent`
// comment
;(async () => {})()
`,
unIndent`
{
let foo
// comment
;(async () => {})()
}
`,
unIndent`
{
let foo
// comment
;(async () => {})()
}
`,
unIndent`
{
// comment
;(async () => {})()
}
`,
unIndent`
{
// comment
;(async () => {})()
}
`,
unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
unIndent`
/* comment */
;[1, 2, 3].forEach(() => {})
`,
unIndent`
/* comment */
;[1, 2, 3].forEach(() => {})
`,
unIndent`
{
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
unIndent`
{
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
unIndent`
{
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
unIndent`
{
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
// import expressions
{
code: unIndent`
import(
// before
source
// after
)
`,
parserOptions: { ecmaVersion: 2020 }
},
// https://github.com/eslint/eslint/issues/12122
{
code: unIndent`
foo(() => {
tag\`
multiline
template
literal
\`(() => {
bar();
});
});
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
{
tag\`
multiline
template
\${a} \${b}
literal
\`(() => {
bar();
});
}
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo(() => {
tagOne\`
multiline
template
literal
\${a} \${b}
\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
});
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
{
tagOne\`
\${a} \${b}
multiline
template
literal
\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
};
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
tagOne\`multiline
\${a} \${b}
template
literal
\`(() => {
foo();
tagTwo\`multiline
template
literal
\`({
bar: 1,
baz: 2
});
});
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
tagOne\`multiline
template
literal
\${a} \${b}\`({
foo: 1,
bar: tagTwo\`multiline
template
literal\`(() => {
baz();
})
});
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar.baz\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar\` template
literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar
.baz\` template
literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo.bar1.bar2\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar1
.bar2\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.bar\`
\${a} \${b}
\`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
baz();
})
`,
options: [4, { MemberExpression: 0 }],
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
baz();
})
`,
options: [4, { MemberExpression: 2 }],
parserOptions: { ecmaVersion: 2015 }
},
{
code: unIndent`
const foo = async (arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
},
{
code: unIndent`
const foo = async /* some comments */(arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
},
{
code: unIndent`
const a = async
b => {}
`,
options: [2]
},
{
code: unIndent`
const foo = (arg1,
arg2) => async (arr1,
arr2) =>
{
return arg1 + arg2;
}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
},
{
code: unIndent`
const foo = async (arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2]
},
{
code: unIndent`
const foo = async /*comments*/(arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2]
},
{
code: unIndent`
const foo = async (arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2, { FunctionDeclaration: { parameters: 4 }, FunctionExpression: { parameters: 4 } }]
},
{
code: unIndent`
const foo = (arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2, { FunctionDeclaration: { parameters: 4 }, FunctionExpression: { parameters: 4 } }]
},
{
code: unIndent`
async function fn(ar1,
ar2){}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
},
{
code: unIndent`
async function /* some comments */ fn(ar1,
ar2){}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
},
{
code: unIndent`
async /* some comments */ function fn(ar1,
ar2){}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }]
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [2],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4, { StaticBlock: { body: 2 } }],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4, { StaticBlock: { body: 0 } }],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
\tstatic {
\t\tfoo();
\t\tbar();
\t}
}
`,
options: ["tab"],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
\tstatic {
\t\t\tfoo();
\t\t\tbar();
\t}
}
`,
options: ["tab", { StaticBlock: { body: 2 } }],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static
{
foo();
bar();
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
var x,
y;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static
{
var x,
y;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
if (foo) {
bar;
}
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
{
bar;
}
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {}
static {
}
static
{
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
static {
foo;
}
static {
bar;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
x = 1;
static {
foo;
}
y = 2;
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
method1(param) {
foo;
}
static {
bar;
}
method2(param) {
foo;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
function f() {
class C {
static {
foo();
bar();
}
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 }
},
{
code: unIndent`
class C {
method() {
foo;
}
static {
bar;
}
}
`,
options: [4, { FunctionExpression: { body: 2 }, StaticBlock: { body: 2 } }],
parserOptions: { ecmaVersion: 2022 }
}
],
invalid: [
{
code: unIndent`
var a = b;
if (a) {
b();
}
`,
output: unIndent`
var a = b;
if (a) {
b();
}
`,
options: [2],
errors: expectedErrors([[3, 2, 0, "Identifier"]])
},
{
code: unIndent`
require('http').request({hostname: 'localhost',
port: 80}, function(res) {
res.end();
});
`,
output: unIndent`
require('http').request({hostname: 'localhost',
port: 80}, function(res) {
res.end();
});
`,
options: [2],
errors: expectedErrors([[2, 2, 18, "Identifier"], [3, 2, 4, "Identifier"], [4, 0, 2, "Punctuator"]])
},
{
code: unIndent`
if (array.some(function(){
return true;
})) {
a++; // ->
b++;
c++; // <-
}
`,
output: unIndent`
if (array.some(function(){
return true;
})) {
a++; // ->
b++;
c++; // <-
}
`,
options: [2],
errors: expectedErrors([[4, 2, 0, "Identifier"], [6, 2, 4, "Identifier"]])
},
{
code: unIndent`
if (a){
\tb=c;
\t\tc=d;
e=f;
}
`,
output: unIndent`
if (a){
\tb=c;
\tc=d;
\te=f;
}
`,
options: ["tab"],
errors: expectedErrors("tab", [[3, 1, 2, "Identifier"], [4, 1, 0, "Identifier"]])
},
{
code: unIndent`
if (a){
b=c;
c=d;
e=f;
}
`,
output: unIndent`
if (a){
b=c;
c=d;
e=f;
}
`,
options: [4],
errors: expectedErrors([[3, 4, 6, "Identifier"], [4, 4, 1, "Identifier"]])
},
{
code: fixture,
output: fixedFixture,
options: [2, { SwitchCase: 1, MemberExpression: 1, CallExpression: { arguments: "off" } }],
errors: expectedErrors([
[5, 2, 4, "Keyword"],
[6, 2, 0, "Line"],
[10, 4, 6, "Punctuator"],
[11, 2, 4, "Punctuator"],
[15, 4, 2, "Identifier"],
[16, 2, 4, "Punctuator"],
[23, 2, 4, "Punctuator"],
[29, 2, 4, "Keyword"],
[30, 4, 6, "Identifier"],
[36, 4, 6, "Identifier"],
[38, 2, 4, "Punctuator"],
[39, 4, 2, "Identifier"],
[40, 2, 0, "Punctuator"],
[54, 2, 4, "Punctuator"],
[114, 4, 2, "Keyword"],
[120, 4, 6, "Keyword"],
[124, 4, 2, "Keyword"],
[134, 4, 6, "Keyword"],
[138, 2, 3, "Punctuator"],
[139, 2, 3, "Punctuator"],
[143, 4, 0, "Identifier"],
[144, 6, 2, "Punctuator"],
[145, 6, 2, "Punctuator"],
[151, 4, 6, "Identifier"],
[152, 6, 8, "Punctuator"],
[153, 6, 8, "Punctuator"],
[159, 4, 2, "Identifier"],
[161, 4, 6, "Identifier"],
[175, 2, 0, "Identifier"],
[177, 2, 4, "Identifier"],
[189, 2, 0, "Keyword"],
[192, 6, 18, "Identifier"],
[193, 6, 4, "Identifier"],
[195, 6, 8, "Identifier"],
[228, 5, 4, "Identifier"],
[231, 3, 2, "Punctuator"],
[245, 0, 2, "Punctuator"],
[248, 0, 2, "Punctuator"],
[304, 4, 6, "Identifier"],
[306, 4, 8, "Identifier"],
[307, 2, 4, "Punctuator"],
[308, 2, 4, "Identifier"],
[311, 4, 6, "Identifier"],
[312, 4, 6, "Identifier"],
[313, 4, 6, "Identifier"],
[314, 2, 4, "Punctuator"],
[315, 2, 4, "Identifier"],
[318, 4, 6, "Identifier"],
[319, 4, 6, "Identifier"],
[320, 4, 6, "Identifier"],
[321, 2, 4, "Punctuator"],
[322, 2, 4, "Identifier"],
[326, 2, 1, "Numeric"],
[327, 2, 1, "Numeric"],
[328, 2, 1, "Numeric"],
[329, 2, 1, "Numeric"],
[330, 2, 1, "Numeric"],
[331, 2, 1, "Numeric"],
[332, 2, 1, "Numeric"],
[333, 2, 1, "Numeric"],
[334, 2, 1, "Numeric"],
[335, 2, 1, "Numeric"],
[340, 2, 4, "Identifier"],
[341, 2, 0, "Identifier"],
[344, 2, 4, "Identifier"],
[345, 2, 0, "Identifier"],
[348, 2, 4, "Identifier"],
[349, 2, 0, "Identifier"],
[355, 2, 0, "Identifier"],
[357, 2, 4, "Identifier"],
[361, 4, 6, "Identifier"],
[362, 2, 4, "Punctuator"],
[363, 2, 4, "Identifier"],
[368, 2, 0, "Keyword"],
[370, 2, 4, "Keyword"],
[374, 4, 6, "Keyword"],
[376, 4, 2, "Keyword"],
[383, 2, 0, "Identifier"],
[385, 2, 4, "Identifier"],
[390, 2, 0, "Identifier"],
[392, 2, 4, "Identifier"],
[409, 2, 0, "Identifier"],
[410, 2, 4, "Identifier"],
[416, 2, 0, "Identifier"],
[417, 2, 4, "Identifier"],
[418, 0, 4, "Punctuator"],
[422, 2, 4, "Identifier"],
[423, 2, 0, "Identifier"],
[427, 2, 6, "Identifier"],
[428, 2, 8, "Identifier"],
[429, 2, 4, "Identifier"],
[430, 0, 4, "Punctuator"],
[433, 2, 4, "Identifier"],
[434, 0, 4, "Punctuator"],
[437, 2, 0, "Identifier"],
[438, 0, 4, "Punctuator"],
[442, 2, 4, "Identifier"],
[443, 2, 4, "Identifier"],
[444, 0, 2, "Punctuator"],
[451, 2, 0, "Identifier"],
[453, 2, 4, "Identifier"],
[499, 6, 8, "Punctuator"],
[500, 8, 6, "Identifier"],
[504, 4, 6, "Punctuator"],
[505, 6, 8, "Identifier"],
[506, 4, 8, "Punctuator"]
])
},
{
code: unIndent`
switch(value){
case "1":
a();
break;
case "2":
a();
break;
default:
a();
break;
}
`,
output: unIndent`
switch(value){
case "1":
a();
break;
case "2":
a();
break;
default:
a();
break;
}
`,
options: [4, { SwitchCase: 1 }],
errors: expectedErrors([[4, 8, 4, "Keyword"], [7, 8, 4, "Keyword"]])
},
{
code: unIndent`
var x = 0 &&
{
a: 1,
b: 2
};
`,
output: unIndent`
var x = 0 &&
{
a: 1,
b: 2
};
`,
options: [4],
errors: expectedErrors([[3, 8, 7, "Identifier"], [4, 8, 10, "Identifier"]])
},
{
code: unIndent`
switch(value){
case "1":
a();
break;
case "2":
a();
break;
default:
break;
}
`,
output: unIndent`
switch(value){
case "1":
a();
break;
case "2":
a();
break;
default:
break;
}
`,
options: [4, { SwitchCase: 1 }],
errors: expectedErrors([9, 8, 4, "Keyword"])
},
{
code: unIndent`
switch(value){
case "1":
case "2":
a();
break;
default:
break;
}
switch(value){
case "1":
break;
case "2":
a();
break;
default:
a();
break;
}
`,
output: unIndent`
switch(value){
case "1":
case "2":
a();
break;
default:
break;
}
switch(value){
case "1":
break;
case "2":
a();
break;
default:
a();
break;
}
`,
options: [4, { SwitchCase: 1 }],
errors: expectedErrors([[11, 8, 4, "Keyword"], [14, 8, 4, "Keyword"], [17, 8, 4, "Keyword"]])
},
{
code: unIndent`
switch(value){
case "1":
a();
break;
case "2":
break;
default:
break;
}
`,
output: unIndent`
switch(value){
case "1":
a();
break;
case "2":
break;
default:
break;
}
`,
options: [4],
errors: expectedErrors([
[3, 4, 8, "Identifier"],
[4, 4, 8, "Keyword"],
[5, 0, 4, "Keyword"],
[6, 4, 8, "Keyword"],
[7, 0, 4, "Keyword"],
[8, 4, 8, "Keyword"]
])
},
{
code: unIndent`
var obj = {foo: 1, bar: 2};
with (obj) {
console.log(foo + bar);
}
`,
output: unIndent`
var obj = {foo: 1, bar: 2};
with (obj) {
console.log(foo + bar);
}
`,
errors: expectedErrors([3, 4, 0, "Identifier"])
},
{
code: unIndent`
switch (a) {
case '1':
b();
break;
default:
c();
break;
}
`,
output: unIndent`
switch (a) {
case '1':
b();
break;
default:
c();
break;
}
`,
options: [4, { SwitchCase: 1 }],
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 8, 0, "Identifier"],
[4, 8, 0, "Keyword"],
[5, 4, 0, "Keyword"],
[6, 8, 0, "Identifier"],
[7, 8, 0, "Keyword"]
])
},
{
code: unIndent`
var foo = function(){
foo
.bar
}
`,
output: unIndent`
var foo = function(){
foo
.bar
}
`,
options: [4, { MemberExpression: 1 }],
errors: expectedErrors(
[3, 8, 10, "Punctuator"]
)
},
{
code: unIndent`
(
foo
.bar
)
`,
output: unIndent`
(
foo
.bar
)
`,
errors: expectedErrors([3, 8, 4, "Punctuator"])
},
{
code: unIndent`
var foo = function(){
foo
.bar
}
`,
output: unIndent`
var foo = function(){
foo
.bar
}
`,
options: [4, { MemberExpression: 2 }],
errors: expectedErrors(
[3, 12, 13, "Punctuator"]
)
},
{
code: unIndent`
var foo = () => {
foo
.bar
}
`,
output: unIndent`
var foo = () => {
foo
.bar
}
`,
options: [4, { MemberExpression: 2 }],
errors: expectedErrors(
[3, 12, 13, "Punctuator"]
)
},
{
code: unIndent`
TestClass.prototype.method = function () {
return Promise.resolve(3)
.then(function (x) {
return x;
});
};
`,
output: unIndent`
TestClass.prototype.method = function () {
return Promise.resolve(3)
.then(function (x) {
return x;
});
};
`,
options: [2, { MemberExpression: 1 }],
errors: expectedErrors([3, 4, 6, "Punctuator"])
},
{
code: unIndent`
while (a)
b();
`,
output: unIndent`
while (a)
b();
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
lmn = [{
a: 1
},
{
b: 2
},
{
x: 2
}];
`,
output: unIndent`
lmn = [{
a: 1
},
{
b: 2
},
{
x: 2
}];
`,
errors: expectedErrors([
[2, 4, 8, "Identifier"],
[3, 0, 4, "Punctuator"],
[4, 0, 4, "Punctuator"],
[5, 4, 8, "Identifier"],
[6, 0, 4, "Punctuator"],
[7, 0, 4, "Punctuator"],
[8, 4, 8, "Identifier"]
])
},
{
code: unIndent`
for (var foo = 1;
foo < 10;
foo++) {}
`,
output: unIndent`
for (var foo = 1;
foo < 10;
foo++) {}
`,
errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 0, "Identifier"]])
},
{
code: unIndent`
for (
var foo = 1;
foo < 10;
foo++
) {}
`,
output: unIndent`
for (
var foo = 1;
foo < 10;
foo++
) {}
`,
errors: expectedErrors([[2, 4, 0, "Keyword"], [3, 4, 0, "Identifier"], [4, 4, 0, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
for (;;)
b();
`,
output: unIndent`
for (;;)
b();
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
for (a in x)
b();
`,
output: unIndent`
for (a in x)
b();
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
do
b();
while(true)
`,
output: unIndent`
do
b();
while(true)
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
if(true)
b();
`,
output: unIndent`
if(true)
b();
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"]
])
},
{
code: unIndent`
var test = {
a: 1,
b: 2
};
`,
output: unIndent`
var test = {
a: 1,
b: 2
};
`,
options: [2],
errors: expectedErrors([
[2, 2, 6, "Identifier"],
[3, 2, 4, "Identifier"],
[4, 0, 4, "Punctuator"]
])
},
{
code: unIndent`
var a = function() {
a++;
b++;
c++;
},
b;
`,
output: unIndent`
var a = function() {
a++;
b++;
c++;
},
b;
`,
options: [4],
errors: expectedErrors([
[2, 8, 6, "Identifier"],
[3, 8, 4, "Identifier"],
[4, 8, 10, "Identifier"]
])
},
{
code: unIndent`
var a = 1,
b = 2,
c = 3;
`,
output: unIndent`
var a = 1,
b = 2,
c = 3;
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 4, 0, "Identifier"]
])
},
{
code: unIndent`
[a, b,
c].forEach((index) => {
index;
});
`,
output: unIndent`
[a, b,
c].forEach((index) => {
index;
});
`,
options: [4],
errors: expectedErrors([
[3, 4, 8, "Identifier"],
[4, 0, 4, "Punctuator"]
])
},
{
code: unIndent`
[a, b,
c].forEach(function(index){
return index;
});
`,
output: unIndent`
[a, b,
c].forEach(function(index){
return index;
});
`,
options: [4],
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 4, 2, "Keyword"]
])
},
{
code: unIndent`
[a, b, c].forEach(function(index){
return index;
});
`,
output: unIndent`
[a, b, c].forEach(function(index){
return index;
});
`,
options: [4],
errors: expectedErrors([
[2, 4, 2, "Keyword"]
])
},
{
code: unIndent`
(foo)
.bar([
baz
]);
`,
output: unIndent`
(foo)
.bar([
baz
]);
`,
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[3, 8, 4, "Identifier"], [4, 4, 0, "Punctuator"]])
},
{
code: unIndent`
var x = ['a',
'b',
'c'
];
`,
output: unIndent`
var x = ['a',
'b',
'c'
];
`,
options: [4],
errors: expectedErrors([
[2, 4, 9, "String"],
[3, 4, 9, "String"]
])
},
{
code: unIndent`
var x = [
'a',
'b',
'c'
];
`,
output: unIndent`
var x = [
'a',
'b',
'c'
];
`,
options: [4],
errors: expectedErrors([
[2, 4, 9, "String"],
[3, 4, 9, "String"],
[4, 4, 9, "String"]
])
},
{
code: unIndent`
var x = [
'a',
'b',
'c',
'd'];
`,
output: unIndent`
var x = [
'a',
'b',
'c',
'd'];
`,
options: [4],
errors: expectedErrors([
[2, 4, 9, "String"],
[3, 4, 9, "String"],
[4, 4, 9, "String"],
[5, 4, 0, "String"]
])
},
{
code: unIndent`
var x = [
'a',
'b',
'c'
];
`,
output: unIndent`
var x = [
'a',
'b',
'c'
];
`,
options: [4],
errors: expectedErrors([
[2, 4, 9, "String"],
[3, 4, 9, "String"],
[4, 4, 9, "String"],
[5, 0, 2, "Punctuator"]
])
},
{
code: unIndent`
[[
], function(
foo
) {}
]
`,
output: unIndent`
[[
], function(
foo
) {}
]
`,
errors: expectedErrors([[3, 4, 8, "Identifier"], [4, 0, 4, "Punctuator"]])
},
{
code: unIndent`
define([
'foo'
], function(
bar
) {
baz;
}
)
`,
output: unIndent`
define([
'foo'
], function(
bar
) {
baz;
}
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
while (1 < 2)
console.log('foo')
console.log('bar')
`,
output: unIndent`
while (1 < 2)
console.log('foo')
console.log('bar')
`,
options: [2],
errors: expectedErrors([
[2, 2, 0, "Identifier"],
[3, 0, 2, "Identifier"]
])
},
{
code: unIndent`
function salutation () {
switch (1) {
case 0: return console.log('hi')
case 1: return console.log('hey')
}
}
`,
output: unIndent`
function salutation () {
switch (1) {
case 0: return console.log('hi')
case 1: return console.log('hey')
}
}
`,
options: [2, { SwitchCase: 1 }],
errors: expectedErrors([
[3, 4, 2, "Keyword"]
])
},
{
code: unIndent`
var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth,
height, rotate;
`,
output: unIndent`
var geometry, box, face1, face2, colorT, colorB, sprite, padding, maxWidth,
height, rotate;
`,
options: [2, { SwitchCase: 1 }],
errors: expectedErrors([
[2, 2, 0, "Identifier"]
])
},
{
code: unIndent`
switch (a) {
case '1':
b();
break;
default:
c();
break;
}
`,
output: unIndent`
switch (a) {
case '1':
b();
break;
default:
c();
break;
}
`,
options: [4, { SwitchCase: 2 }],
errors: expectedErrors([
[2, 8, 0, "Keyword"],
[3, 12, 0, "Identifier"],
[4, 12, 0, "Keyword"],
[5, 8, 0, "Keyword"],
[6, 12, 0, "Identifier"],
[7, 12, 0, "Keyword"]
])
},
{
code: unIndent`
var geometry,
rotate;
`,
output: unIndent`
var geometry,
rotate;
`,
options: [2, { VariableDeclarator: 1 }],
errors: expectedErrors([
[2, 2, 0, "Identifier"]
])
},
{
code: unIndent`
var geometry,
rotate;
`,
output: unIndent`
var geometry,
rotate;
`,
options: [2, { VariableDeclarator: 2 }],
errors: expectedErrors([
[2, 4, 2, "Identifier"]
])
},
{
code: unIndent`
var geometry,
\trotate;
`,
output: unIndent`
var geometry,
\t\trotate;
`,
options: ["tab", { VariableDeclarator: 2 }],
errors: expectedErrors("tab", [
[2, 2, 1, "Identifier"]
])
},
{
code: unIndent`
let geometry,
rotate;
`,
output: unIndent`
let geometry,
rotate;
`,
options: [2, { VariableDeclarator: 2 }],
errors: expectedErrors([
[2, 4, 2, "Identifier"]
])
},
{
code: unIndent`
let foo = 'foo',
bar = bar;
const a = 'a',
b = 'b';
`,
output: unIndent`
let foo = 'foo',
bar = bar;
const a = 'a',
b = 'b';
`,
options: [2, { VariableDeclarator: "first" }],
errors: expectedErrors([
[2, 4, 2, "Identifier"],
[4, 6, 2, "Identifier"]
])
},
{
code: unIndent`
var foo = 'foo',
bar = bar;
`,
output: unIndent`
var foo = 'foo',
bar = bar;
`,
options: [2, { VariableDeclarator: { var: "first" } }],
errors: expectedErrors([
[2, 4, 2, "Identifier"]
])
},
{
code: unIndent`
if(true)
if (true)
if (true)
console.log(val);
`,
output: unIndent`
if(true)
if (true)
if (true)
console.log(val);
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([
[4, 6, 4, "Identifier"]
])
},
{
code: unIndent`
var a = {
a: 1,
b: 2
}
`,
output: unIndent`
var a = {
a: 1,
b: 2
}
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([
[2, 2, 4, "Identifier"],
[3, 2, 4, "Identifier"]
])
},
{
code: unIndent`
var a = [
a,
b
]
`,
output: unIndent`
var a = [
a,
b
]
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([
[2, 2, 4, "Identifier"],
[3, 2, 4, "Identifier"]
])
},
{
code: unIndent`
let a = [
a,
b
]
`,
output: unIndent`
let a = [
a,
b
]
`,
options: [2, { VariableDeclarator: { let: 2 }, SwitchCase: 1 }],
errors: expectedErrors([
[2, 2, 4, "Identifier"],
[3, 2, 4, "Identifier"]
])
},
{
code: unIndent`
var a = new Test({
a: 1
}),
b = 4;
`,
output: unIndent`
var a = new Test({
a: 1
}),
b = 4;
`,
options: [4],
errors: expectedErrors([
[2, 8, 6, "Identifier"],
[3, 4, 2, "Punctuator"]
])
},
{
code: unIndent`
var a = new Test({
a: 1
}),
b = 4;
const c = new Test({
a: 1
}),
d = 4;
`,
output: unIndent`
var a = new Test({
a: 1
}),
b = 4;
const c = new Test({
a: 1
}),
d = 4;
`,
options: [2, { VariableDeclarator: { var: 2 } }],
errors: expectedErrors([
[6, 4, 6, "Identifier"],
[7, 2, 4, "Punctuator"],
[8, 2, 4, "Identifier"]
])
},
{
code: unIndent`
var abc = 5,
c = 2,
xyz =
{
a: 1,
b: 2
};
`,
output: unIndent`
var abc = 5,
c = 2,
xyz =
{
a: 1,
b: 2
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([6, 6, 7, "Identifier"])
},
{
code: unIndent`
var abc =
{
a: 1,
b: 2
};
`,
output: unIndent`
var abc =
{
a: 1,
b: 2
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([4, 7, 8, "Identifier"])
},
{
code: unIndent`
var foo = {
bar: 1,
baz: {
qux: 2
}
},
bar = 1;
`,
output: unIndent`
var foo = {
bar: 1,
baz: {
qux: 2
}
},
bar = 1;
`,
options: [2],
errors: expectedErrors([[4, 6, 8, "Identifier"], [5, 4, 6, "Punctuator"]])
},
{
code: unIndent`
var path = require('path')
, crypto = require('crypto')
;
`,
output: unIndent`
var path = require('path')
, crypto = require('crypto')
;
`,
options: [2],
errors: expectedErrors([
[2, 2, 1, "Punctuator"]
])
},
{
code: unIndent`
var a = 1
,b = 2
;
`,
output: unIndent`
var a = 1
,b = 2
;
`,
errors: expectedErrors([
[2, 4, 3, "Punctuator"]
])
},
{
code: unIndent`
class A{
constructor(){}
a(){}
get b(){}
}
`,
output: unIndent`
class A{
constructor(){}
a(){}
get b(){}
}
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }],
errors: expectedErrors([[2, 4, 2, "Identifier"]])
},
{
code: unIndent`
var A = class {
constructor(){}
a(){}
get b(){}
};
`,
output: unIndent`
var A = class {
constructor(){}
a(){}
get b(){}
};
`,
options: [4, { VariableDeclarator: 1, SwitchCase: 1 }],
errors: expectedErrors([[2, 4, 2, "Identifier"], [4, 4, 2, "Identifier"]])
},
{
code: unIndent`
var a = 1,
B = class {
constructor(){}
a(){}
get b(){}
};
`,
output: unIndent`
var a = 1,
B = class {
constructor(){}
a(){}
get b(){}
};
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([[3, 6, 4, "Identifier"]])
},
{
code: unIndent`
{
if(a){
foo();
}
else{
bar();
}
}
`,
output: unIndent`
{
if(a){
foo();
}
else{
bar();
}
}
`,
options: [4],
errors: expectedErrors([[5, 4, 2, "Keyword"]])
},
{
code: unIndent`
{
if(a){
foo();
}
else
bar();
}
`,
output: unIndent`
{
if(a){
foo();
}
else
bar();
}
`,
options: [4],
errors: expectedErrors([[5, 4, 2, "Keyword"]])
},
{
code: unIndent`
{
if(a)
foo();
else
bar();
}
`,
output: unIndent`
{
if(a)
foo();
else
bar();
}
`,
options: [4],
errors: expectedErrors([[4, 4, 2, "Keyword"]])
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
output: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
options: [2, { outerIIFEBody: 0 }],
errors: expectedErrors([[2, 0, 2, "Keyword"], [3, 2, 4, "Keyword"], [4, 0, 2, "Punctuator"]])
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
output: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
options: [4, { outerIIFEBody: 2 }],
errors: expectedErrors([[2, 8, 4, "Keyword"], [3, 12, 8, "Keyword"], [4, 8, 4, "Punctuator"]])
},
{
code: unIndent`
if(data) {
console.log('hi');
}
`,
output: unIndent`
if(data) {
console.log('hi');
}
`,
options: [2, { outerIIFEBody: 0 }],
errors: expectedErrors([[2, 2, 0, "Identifier"]])
},
{
code: unIndent`
var ns = function(){
function fooVar(x) {
return x + 1;
}
}(x);
`,
output: unIndent`
var ns = function(){
function fooVar(x) {
return x + 1;
}
}(x);
`,
options: [4, { outerIIFEBody: 2 }],
errors: expectedErrors([[2, 8, 4, "Keyword"], [3, 12, 8, "Keyword"], [4, 8, 4, "Punctuator"]])
},
{
code: unIndent`
var obj = {
foo: function() {
return true;
}()
};
`,
output: unIndent`
var obj = {
foo: function() {
return true;
}()
};
`,
options: [2, { outerIIFEBody: 0 }],
errors: expectedErrors([[3, 4, 2, "Keyword"]])
},
{
code: unIndent`
typeof function() {
function fooVar(x) {
return x + 1;
}
}();
`,
output: unIndent`
typeof function() {
function fooVar(x) {
return x + 1;
}
}();
`,
options: [2, { outerIIFEBody: 2 }],
errors: expectedErrors([[2, 2, 4, "Keyword"], [3, 4, 6, "Keyword"], [4, 2, 4, "Punctuator"]])
},
{
code: unIndent`
{
\t!function(x) {
\t\t\t\treturn x + 1;
\t}()
};
`,
output: unIndent`
{
\t!function(x) {
\t\treturn x + 1;
\t}()
};
`,
options: ["tab", { outerIIFEBody: 3 }],
errors: expectedErrors("tab", [[3, 2, 4, "Keyword"]])
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
output: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
options: [4, { outerIIFEBody: "off" }],
errors: expectedErrors([[3, 8, 4, "Keyword"]])
},
{
code: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
output: unIndent`
(function(){
function foo(x) {
return x + 1;
}
})();
`,
options: [4, { outerIIFEBody: "off" }],
errors: expectedErrors([[3, 4, 0, "Keyword"]])
},
{
code: unIndent`
(() => {
function foo(x) {
return x + 1;
}
})();
`,
output: unIndent`
(() => {
function foo(x) {
return x + 1;
}
})();
`,
options: [4, { outerIIFEBody: "off" }],
errors: expectedErrors([[3, 8, 4, "Keyword"]])
},
{
code: unIndent`
(() => {
function foo(x) {
return x + 1;
}
})();
`,
output: unIndent`
(() => {
function foo(x) {
return x + 1;
}
})();
`,
options: [4, { outerIIFEBody: "off" }],
errors: expectedErrors([[3, 4, 0, "Keyword"]])
},
{
code: unIndent`
Buffer
.toString()
`,
output: unIndent`
Buffer
.toString()
`,
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[2, 4, 0, "Punctuator"]])
},
{
code: unIndent`
Buffer
.indexOf('a')
.toString()
`,
output: unIndent`
Buffer
.indexOf('a')
.toString()
`,
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[3, 4, 0, "Punctuator"]])
},
{
code: unIndent`
Buffer.
length
`,
output: unIndent`
Buffer.
length
`,
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([[2, 4, 0, "Identifier"]])
},
{
code: unIndent`
Buffer.
\t\tlength
`,
output: unIndent`
Buffer.
\tlength
`,
options: ["tab", { MemberExpression: 1 }],
errors: expectedErrors("tab", [[2, 1, 2, "Identifier"]])
},
{
code: unIndent`
Buffer
.foo
.bar
`,
output: unIndent`
Buffer
.foo
.bar
`,
options: [2, { MemberExpression: 2 }],
errors: expectedErrors([[2, 4, 2, "Punctuator"], [3, 4, 2, "Punctuator"]])
},
{
code: unIndent`
function foo() {
new
.target
}
`,
output: unIndent`
function foo() {
new
.target
}
`,
errors: expectedErrors([3, 8, 4, "Punctuator"])
},
{
code: unIndent`
function foo() {
new.
target
}
`,
output: unIndent`
function foo() {
new.
target
}
`,
errors: expectedErrors([3, 8, 4, "Identifier"])
},
{
// Indentation with multiple else statements: https://github.com/eslint/eslint/issues/6956
code: unIndent`
if (foo) bar();
else if (baz) foobar();
else if (qux) qux();
`,
output: unIndent`
if (foo) bar();
else if (baz) foobar();
else if (qux) qux();
`,
options: [2],
errors: expectedErrors([3, 0, 2, "Keyword"])
},
{
code: unIndent`
if (foo) bar();
else if (baz) foobar();
else qux();
`,
output: unIndent`
if (foo) bar();
else if (baz) foobar();
else qux();
`,
options: [2],
errors: expectedErrors([3, 0, 2, "Keyword"])
},
{
code: unIndent`
foo();
if (baz) foobar();
else qux();
`,
output: unIndent`
foo();
if (baz) foobar();
else qux();
`,
options: [2],
errors: expectedErrors([[2, 0, 2, "Keyword"], [3, 0, 2, "Keyword"]])
},
{
code: unIndent`
if (foo) bar();
else if (baz) foobar();
else if (bip) {
qux();
}
`,
output: unIndent`
if (foo) bar();
else if (baz) foobar();
else if (bip) {
qux();
}
`,
options: [2],
errors: expectedErrors([[3, 0, 5, "Keyword"], [4, 2, 7, "Identifier"], [5, 0, 5, "Punctuator"]])
},
{
code: unIndent`
if (foo) bar();
else if (baz) {
foobar();
} else if (boop) {
qux();
}
`,
output: unIndent`
if (foo) bar();
else if (baz) {
foobar();
} else if (boop) {
qux();
}
`,
options: [2],
errors: expectedErrors([[3, 2, 4, "Identifier"], [4, 0, 5, "Punctuator"], [5, 2, 7, "Identifier"], [6, 0, 5, "Punctuator"]])
},
{
code: unIndent`
function foo(aaa,
bbb, ccc, ddd) {
bar();
}
`,
output: unIndent`
function foo(aaa,
bbb, ccc, ddd) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: 1, body: 2 } }],
errors: expectedErrors([[2, 2, 4, "Identifier"], [3, 4, 6, "Identifier"]])
},
{
code: unIndent`
function foo(aaa, bbb,
ccc, ddd) {
bar();
}
`,
output: unIndent`
function foo(aaa, bbb,
ccc, ddd) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: 3, body: 1 } }],
errors: expectedErrors([[2, 6, 2, "Identifier"], [3, 2, 0, "Identifier"]])
},
{
code: unIndent`
function foo(aaa,
bbb,
ccc) {
bar();
}
`,
output: unIndent`
function foo(aaa,
bbb,
ccc) {
bar();
}
`,
options: [4, { FunctionDeclaration: { parameters: 1, body: 3 } }],
errors: expectedErrors([[2, 4, 8, "Identifier"], [3, 4, 2, "Identifier"], [4, 12, 6, "Identifier"]])
},
{
code: unIndent`
function foo(aaa,
bbb, ccc,
ddd, eee, fff) {
bar();
}
`,
output: unIndent`
function foo(aaa,
bbb, ccc,
ddd, eee, fff) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: "first", body: 1 } }],
errors: expectedErrors([[2, 13, 2, "Identifier"], [3, 13, 19, "Identifier"], [4, 2, 3, "Identifier"]])
},
{
code: unIndent`
function foo(aaa, bbb)
{
bar();
}
`,
output: unIndent`
function foo(aaa, bbb)
{
bar();
}
`,
options: [2, { FunctionDeclaration: { body: 3 } }],
errors: expectedErrors([3, 6, 0, "Identifier"])
},
{
code: unIndent`
function foo(
aaa,
bbb) {
bar();
}
`,
output: unIndent`
function foo(
aaa,
bbb) {
bar();
}
`,
options: [2, { FunctionDeclaration: { parameters: "first", body: 2 } }],
errors: expectedErrors([[2, 2, 0, "Identifier"], [3, 2, 4, "Identifier"], [4, 4, 0, "Identifier"]])
},
{
code: unIndent`
var foo = function(aaa,
bbb,
ccc,
ddd) {
bar();
}
`,
output: unIndent`
var foo = function(aaa,
bbb,
ccc,
ddd) {
bar();
}
`,
options: [2, { FunctionExpression: { parameters: 2, body: 0 } }],
errors: expectedErrors([[2, 4, 2, "Identifier"], [4, 4, 6, "Identifier"], [5, 0, 2, "Identifier"]])
},
{
code: unIndent`
var foo = function(aaa,
bbb,
ccc) {
bar();
}
`,
output: unIndent`
var foo = function(aaa,
bbb,
ccc) {
bar();
}
`,
options: [2, { FunctionExpression: { parameters: 1, body: 10 } }],
errors: expectedErrors([[2, 2, 3, "Identifier"], [3, 2, 1, "Identifier"], [4, 20, 2, "Identifier"]])
},
{
code: unIndent`
var foo = function(aaa,
bbb, ccc, ddd,
eee, fff) {
bar();
}
`,
output: unIndent`
var foo = function(aaa,
bbb, ccc, ddd,
eee, fff) {
bar();
}
`,
options: [4, { FunctionExpression: { parameters: "first", body: 1 } }],
errors: expectedErrors([[2, 19, 2, "Identifier"], [3, 19, 24, "Identifier"], [4, 4, 8, "Identifier"]])
},
{
code: unIndent`
var foo = function(
aaa, bbb, ccc,
ddd, eee) {
bar();
}
`,
output: unIndent`
var foo = function(
aaa, bbb, ccc,
ddd, eee) {
bar();
}
`,
options: [2, { FunctionExpression: { parameters: "first", body: 3 } }],
errors: expectedErrors([[2, 2, 0, "Identifier"], [3, 2, 4, "Identifier"], [4, 6, 2, "Identifier"]])
},
{
code: unIndent`
var foo = bar;
\t\t\tvar baz = qux;
`,
output: unIndent`
var foo = bar;
var baz = qux;
`,
options: [2],
errors: expectedErrors([2, "0 spaces", "3 tabs", "Keyword"])
},
{
code: unIndent`
function foo() {
\tbar();
baz();
qux();
}
`,
output: unIndent`
function foo() {
\tbar();
\tbaz();
\tqux();
}
`,
options: ["tab"],
errors: expectedErrors("tab", [[3, "1 tab", "2 spaces", "Identifier"], [4, "1 tab", "14 spaces", "Identifier"]])
},
{
code: unIndent`
function foo() {
bar();
\t\t}
`,
output: unIndent`
function foo() {
bar();
}
`,
options: [2],
errors: expectedErrors([[3, "0 spaces", "2 tabs", "Punctuator"]])
},
{
code: unIndent`
function foo() {
function bar() {
baz();
}
}
`,
output: unIndent`
function foo() {
function bar() {
baz();
}
}
`,
options: [2, { FunctionDeclaration: { body: 1 } }],
errors: expectedErrors([3, 4, 8, "Identifier"])
},
{
code: unIndent`
function foo() {
function bar(baz,
qux) {
foobar();
}
}
`,
output: unIndent`
function foo() {
function bar(baz,
qux) {
foobar();
}
}
`,
options: [2, { FunctionDeclaration: { body: 1, parameters: 2 } }],
errors: expectedErrors([3, 6, 4, "Identifier"])
},
{
code: unIndent`
function foo() {
var bar = function(baz,
qux) {
foobar();
};
}
`,
output: unIndent`
function foo() {
var bar = function(baz,
qux) {
foobar();
};
}
`,
options: [2, { FunctionExpression: { parameters: 3 } }],
errors: expectedErrors([3, 8, 10, "Identifier"])
},
{
code: unIndent`
foo.bar(
baz, qux, function() {
qux;
}
);
`,
output: unIndent`
foo.bar(
baz, qux, function() {
qux;
}
);
`,
options: [2, { FunctionExpression: { body: 3 }, CallExpression: { arguments: 3 } }],
errors: expectedErrors([3, 12, 8, "Identifier"])
},
{
code: unIndent`
{
try {
}
catch (err) {
}
finally {
}
}
`,
output: unIndent`
{
try {
}
catch (err) {
}
finally {
}
}
`,
errors: expectedErrors([
[4, 4, 0, "Keyword"],
[6, 4, 0, "Keyword"]
])
},
{
code: unIndent`
{
do {
}
while (true)
}
`,
output: unIndent`
{
do {
}
while (true)
}
`,
errors: expectedErrors([4, 4, 0, "Keyword"])
},
{
code: unIndent`
function foo() {
return (
1
)
}
`,
output: unIndent`
function foo() {
return (
1
)
}
`,
options: [2],
errors: expectedErrors([[4, 2, 4, "Punctuator"]])
},
{
code: unIndent`
function foo() {
return (
1
);
}
`,
output: unIndent`
function foo() {
return (
1
);
}
`,
options: [2],
errors: expectedErrors([[4, 2, 4, "Punctuator"]])
},
{
code: unIndent`
function test(){
switch(length){
case 1: return function(a){
return fn.call(that, a);
};
}
}
`,
output: unIndent`
function test(){
switch(length){
case 1: return function(a){
return fn.call(that, a);
};
}
}
`,
options: [2, { VariableDeclarator: 2, SwitchCase: 1 }],
errors: expectedErrors([[4, 6, 4, "Keyword"]])
},
{
code: unIndent`
function foo() {
return 1
}
`,
output: unIndent`
function foo() {
return 1
}
`,
options: [2],
errors: expectedErrors([[2, 2, 3, "Keyword"]])
},
{
code: unIndent`
foo(
bar,
baz,
qux);
`,
output: unIndent`
foo(
bar,
baz,
qux);
`,
options: [2, { CallExpression: { arguments: 1 } }],
errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"]])
},
{
code: unIndent`
foo(
\tbar,
\tbaz);
`,
output: unIndent`
foo(
bar,
baz);
`,
options: [2, { CallExpression: { arguments: 2 } }],
errors: expectedErrors([[2, "4 spaces", "1 tab", "Identifier"], [3, "4 spaces", "1 tab", "Identifier"]])
},
{
code: unIndent`
foo(bar,
\t\tbaz,
\t\tqux);
`,
output: unIndent`
foo(bar,
\tbaz,
\tqux);
`,
options: ["tab", { CallExpression: { arguments: 1 } }],
errors: expectedErrors("tab", [[2, 1, 2, "Identifier"], [3, 1, 2, "Identifier"]])
},
{
code: unIndent`
foo(bar, baz,
qux);
`,
output: unIndent`
foo(bar, baz,
qux);
`,
options: [2, { CallExpression: { arguments: "first" } }],
errors: expectedErrors([2, 4, 9, "Identifier"])
},
{
code: unIndent`
foo(
bar,
baz);
`,
output: unIndent`
foo(
bar,
baz);
`,
options: [2, { CallExpression: { arguments: "first" } }],
errors: expectedErrors([[2, 2, 10, "Identifier"], [3, 2, 4, "Identifier"]])
},
{
code: unIndent`
foo(bar,
1 + 2,
!baz,
new Car('!')
);
`,
output: unIndent`
foo(bar,
1 + 2,
!baz,
new Car('!')
);
`,
options: [2, { CallExpression: { arguments: 3 } }],
errors: expectedErrors([[2, 6, 2, "Numeric"], [3, 6, 14, "Punctuator"], [4, 6, 8, "Keyword"]])
},
// https://github.com/eslint/eslint/issues/7573
{
code: unIndent`
return (
foo
);
`,
output: unIndent`
return (
foo
);
`,
parserOptions: { ecmaFeatures: { globalReturn: true } },
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
return (
foo
)
`,
output: unIndent`
return (
foo
)
`,
parserOptions: { ecmaFeatures: { globalReturn: true } },
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
// https://github.com/eslint/eslint/issues/7604
{
code: unIndent`
if (foo) {
/* comment */bar();
}
`,
output: unIndent`
if (foo) {
/* comment */bar();
}
`,
errors: expectedErrors([2, 4, 8, "Block"])
},
{
code: unIndent`
foo('bar',
/** comment */{
ok: true
});
`,
output: unIndent`
foo('bar',
/** comment */{
ok: true
});
`,
errors: expectedErrors([2, 4, 8, "Block"])
},
{
code: unIndent`
foo(
(bar)
);
`,
output: unIndent`
foo(
(bar)
);
`,
options: [4, { CallExpression: { arguments: 1 } }],
errors: expectedErrors([2, 4, 0, "Punctuator"])
},
{
code: unIndent`
((
foo
))
`,
output: unIndent`
((
foo
))
`,
options: [4],
errors: expectedErrors([2, 4, 0, "Identifier"])
},
// ternary expressions (https://github.com/eslint/eslint/issues/7420)
{
code: unIndent`
foo
? bar
: baz
`,
output: unIndent`
foo
? bar
: baz
`,
options: [2],
errors: expectedErrors([[2, 2, 0, "Punctuator"], [3, 2, 4, "Punctuator"]])
},
{
code: unIndent`
[
foo ?
bar :
baz,
qux
]
`,
output: unIndent`
[
foo ?
bar :
baz,
qux
]
`,
errors: expectedErrors([5, 4, 8, "Identifier"])
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
output: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [2, { offsetTernaryExpressions: true }],
errors: expectedErrors([
[2, 2, 0, "Punctuator"],
[3, 6, 0, "Keyword"],
[4, 4, 0, "Punctuator"],
[5, 2, 0, "Punctuator"],
[6, 4, 0, "Punctuator"],
[7, 8, 0, "Keyword"],
[8, 6, 0, "Punctuator"],
[9, 4, 0, "Punctuator"],
[10, 8, 0, "Keyword"],
[11, 6, 0, "Punctuator"]
])
},
{
code: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
output: unIndent`
condition
? () => {
return true
}
: condition2
? () => {
return true
}
: () => {
return false
}
`,
options: [2, { offsetTernaryExpressions: false }],
errors: expectedErrors([
[2, 2, 0, "Punctuator"],
[3, 4, 0, "Keyword"],
[4, 2, 0, "Punctuator"],
[5, 2, 0, "Punctuator"],
[6, 4, 0, "Punctuator"],
[7, 6, 0, "Keyword"],
[8, 4, 0, "Punctuator"],
[9, 4, 0, "Punctuator"],
[10, 6, 0, "Keyword"],
[11, 4, 0, "Punctuator"]
])
},
{
/*
* Checking comments:
* https://github.com/eslint/eslint/issues/6571
*/
code: unIndent`
foo();
// comment
/* multiline
comment */
bar();
// trailing comment
`,
output: unIndent`
foo();
// comment
/* multiline
comment */
bar();
// trailing comment
`,
options: [2],
errors: expectedErrors([[2, 0, 2, "Line"], [3, 0, 4, "Block"], [6, 0, 1, "Line"]])
},
{
code: " // comment",
output: "// comment",
errors: expectedErrors([1, 0, 2, "Line"])
},
{
code: unIndent`
foo
// comment
`,
output: unIndent`
foo
// comment
`,
errors: expectedErrors([2, 0, 2, "Line"])
},
{
code: unIndent`
// comment
foo
`,
output: unIndent`
// comment
foo
`,
errors: expectedErrors([1, 0, 2, "Line"])
},
{
code: unIndent`
[
// no elements
]
`,
output: unIndent`
[
// no elements
]
`,
errors: expectedErrors([2, 4, 8, "Line"])
},
{
/*
* Destructuring assignments:
* https://github.com/eslint/eslint/issues/6813
*/
code: unIndent`
var {
foo,
bar,
baz: qux,
foobar: baz = foobar
} = qux;
`,
output: unIndent`
var {
foo,
bar,
baz: qux,
foobar: baz = foobar
} = qux;
`,
options: [2],
errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"], [5, 2, 6, "Identifier"], [6, 0, 2, "Punctuator"]])
},
{
code: unIndent`
const {
a
} = {
a: 1
}
`,
output: unIndent`
const {
a
} = {
a: 1
}
`,
options: [2],
errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
},
{
code: unIndent`
var foo = [
bar,
baz
]
`,
output: unIndent`
var foo = [
bar,
baz
]
`,
errors: expectedErrors([[2, 4, 11, "Identifier"], [3, 4, 2, "Identifier"], [4, 0, 10, "Punctuator"]])
},
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
output: unIndent`
var foo = [bar,
baz,
qux
]
`,
errors: expectedErrors([2, 4, 0, "Identifier"])
},
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
output: unIndent`
var foo = [bar,
baz,
qux
]
`,
options: [2, { ArrayExpression: 0 }],
errors: expectedErrors([[2, 0, 2, "Identifier"], [3, 0, 2, "Identifier"]])
},
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
output: unIndent`
var foo = [bar,
baz,
qux
]
`,
options: [2, { ArrayExpression: 8 }],
errors: expectedErrors([[2, 16, 2, "Identifier"], [3, 16, 2, "Identifier"]])
},
{
code: unIndent`
var foo = [bar,
baz,
qux
]
`,
output: unIndent`
var foo = [bar,
baz,
qux
]
`,
options: [2, { ArrayExpression: "first" }],
errors: expectedErrors([[2, 11, 4, "Identifier"], [3, 11, 4, "Identifier"]])
},
{
code: unIndent`
var foo = [bar,
baz, qux
]
`,
output: unIndent`
var foo = [bar,
baz, qux
]
`,
options: [2, { ArrayExpression: "first" }],
errors: expectedErrors([2, 11, 4, "Identifier"])
},
{
code: unIndent`
var foo = [
{ bar: 1,
baz: 2 },
{ bar: 3,
qux: 4 }
]
`,
output: unIndent`
var foo = [
{ bar: 1,
baz: 2 },
{ bar: 3,
qux: 4 }
]
`,
options: [4, { ArrayExpression: 2, ObjectExpression: "first" }],
errors: expectedErrors([[3, 10, 12, "Identifier"], [5, 10, 12, "Identifier"]])
},
{
code: unIndent`
var foo = {
bar: 1,
baz: 2
};
`,
output: unIndent`
var foo = {
bar: 1,
baz: 2
};
`,
options: [2, { ObjectExpression: 0 }],
errors: expectedErrors([[2, 0, 2, "Identifier"], [3, 0, 2, "Identifier"]])
},
{
code: unIndent`
var quux = { foo: 1, bar: 2,
baz: 3 }
`,
output: unIndent`
var quux = { foo: 1, bar: 2,
baz: 3 }
`,
options: [2, { ObjectExpression: "first" }],
errors: expectedErrors([2, 13, 0, "Identifier"])
},
{
code: unIndent`
function foo() {
[
foo
]
}
`,
output: unIndent`
function foo() {
[
foo
]
}
`,
options: [2, { ArrayExpression: 4 }],
errors: expectedErrors([[2, 2, 4, "Punctuator"], [3, 10, 12, "Identifier"], [4, 2, 4, "Punctuator"]])
},
{
code: unIndent`
var [
foo,
bar,
baz,
foobar = baz
] = qux;
`,
output: unIndent`
var [
foo,
bar,
baz,
foobar = baz
] = qux;
`,
options: [2],
errors: expectedErrors([[2, 2, 0, "Identifier"], [4, 2, 4, "Identifier"], [5, 2, 6, "Identifier"], [6, 0, 2, "Punctuator"]])
},
{
code: unIndent`
import {
foo,
bar,
baz
} from 'qux';
`,
output: unIndent`
import {
foo,
bar,
baz
} from 'qux';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 2, "Identifier"]])
},
{
code: unIndent`
import { foo,
bar,
baz,
} from 'qux';
`,
output: unIndent`
import { foo,
bar,
baz,
} from 'qux';
`,
options: [4, { ImportDeclaration: "first" }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([[3, 9, 10, "Identifier"]])
},
{
code: unIndent`
import { foo,
bar,
baz,
} from 'qux';
`,
output: unIndent`
import { foo,
bar,
baz,
} from 'qux';
`,
options: [2, { ImportDeclaration: 2 }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([[3, 4, 5, "Identifier"]])
},
{
code: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
};
`,
output: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
};
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]])
},
{
code: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
} from 'qux';
`,
output: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
} from 'qux';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 2, "Identifier"]])
},
{
// https://github.com/eslint/eslint/issues/7233
code: unIndent`
var folder = filePath
.foo()
.bar;
`,
output: unIndent`
var folder = filePath
.foo()
.bar;
`,
options: [2, { MemberExpression: 2 }],
errors: expectedErrors([[2, 4, 2, "Punctuator"], [3, 4, 6, "Punctuator"]])
},
{
code: unIndent`
for (const foo of bar)
baz();
`,
output: unIndent`
for (const foo of bar)
baz();
`,
options: [2],
errors: expectedErrors([2, 2, 4, "Identifier"])
},
{
code: unIndent`
var x = () =>
5;
`,
output: unIndent`
var x = () =>
5;
`,
options: [2],
errors: expectedErrors([2, 2, 4, "Numeric"])
},
{
// BinaryExpressions with parens
code: unIndent`
foo && (
bar
)
`,
output: unIndent`
foo && (
bar
)
`,
options: [4],
errors: expectedErrors([2, 4, 8, "Identifier"])
},
{
code: unIndent`
foo &&
!bar(
)
`,
output: unIndent`
foo &&
!bar(
)
`,
errors: expectedErrors([3, 4, 0, "Punctuator"])
},
{
code: unIndent`
foo &&
![].map(() => {
bar();
})
`,
output: unIndent`
foo &&
![].map(() => {
bar();
})
`,
errors: expectedErrors([[3, 8, 4, "Identifier"], [4, 4, 0, "Punctuator"]])
},
{
code: unIndent`
[
] || [
]
`,
output: unIndent`
[
] || [
]
`,
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
foo
|| (
bar
)
`,
output: unIndent`
foo
|| (
bar
)
`,
errors: expectedErrors([[3, 12, 16, "Identifier"], [4, 8, 12, "Punctuator"]])
},
{
code: unIndent`
1
+ (
1
)
`,
output: unIndent`
1
+ (
1
)
`,
errors: expectedErrors([[3, 4, 8, "Numeric"], [4, 0, 4, "Punctuator"]])
},
// Template curlies
{
code: unIndent`
\`foo\${
bar}\`
`,
output: unIndent`
\`foo\${
bar}\`
`,
options: [2],
errors: expectedErrors([2, 2, 0, "Identifier"])
},
{
code: unIndent`
\`foo\${
\`bar\${
baz}\`}\`
`,
output: unIndent`
\`foo\${
\`bar\${
baz}\`}\`
`,
options: [2],
errors: expectedErrors([[2, 2, 4, "Template"], [3, 4, 0, "Identifier"]])
},
{
code: unIndent`
\`foo\${
\`bar\${
baz
}\`
}\`
`,
output: unIndent`
\`foo\${
\`bar\${
baz
}\`
}\`
`,
options: [2],
errors: expectedErrors([[2, 2, 4, "Template"], [3, 4, 2, "Identifier"], [4, 2, 4, "Template"], [5, 0, 2, "Template"]])
},
{
code: unIndent`
\`foo\${
(
bar
)
}\`
`,
output: unIndent`
\`foo\${
(
bar
)
}\`
`,
options: [2],
errors: expectedErrors([[2, 2, 0, "Punctuator"], [3, 4, 2, "Identifier"], [4, 2, 0, "Punctuator"]])
},
{
code: unIndent`
function foo() {
\`foo\${bar}baz\${
qux}foo\${
bar}baz\`
}
`,
output: unIndent`
function foo() {
\`foo\${bar}baz\${
qux}foo\${
bar}baz\`
}
`,
errors: expectedErrors([[3, 8, 0, "Identifier"], [4, 8, 2, "Identifier"]])
},
{
code: unIndent`
function foo() {
const template = \`the indentation of
a curly element in a \${
node.type
} node is checked.\`;
}
`,
output: unIndent`
function foo() {
const template = \`the indentation of
a curly element in a \${
node.type
} node is checked.\`;
}
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Template"]])
},
{
code: unIndent`
function foo() {
const template = \`this time the
closing curly is at the end of the line \${
foo}
so the spaces before this line aren't removed.\`;
}
`,
output: unIndent`
function foo() {
const template = \`this time the
closing curly is at the end of the line \${
foo}
so the spaces before this line aren't removed.\`;
}
`,
errors: expectedErrors([4, 4, 12, "Identifier"])
},
{
/*
* https://github.com/eslint/eslint/issues/1801
* Note: This issue also mentioned checking the indentation for the 2 below. However,
* this is intentionally ignored because everyone seems to have a different idea of how
* BinaryExpressions should be indented.
*/
code: unIndent`
if (true) {
a = (
1 +
2);
}
`,
output: unIndent`
if (true) {
a = (
1 +
2);
}
`,
errors: expectedErrors([3, 8, 0, "Numeric"])
},
{
// https://github.com/eslint/eslint/issues/3737
code: unIndent`
if (true) {
for (;;) {
b();
}
}
`,
output: unIndent`
if (true) {
for (;;) {
b();
}
}
`,
options: [2],
errors: expectedErrors([[2, 2, 4, "Keyword"], [3, 4, 6, "Identifier"]])
},
{
// https://github.com/eslint/eslint/issues/6670
code: unIndent`
function f() {
return asyncCall()
.then(
'some string',
[
1,
2,
3
]
);
}
`,
output: unIndent`
function f() {
return asyncCall()
.then(
'some string',
[
1,
2,
3
]
);
}
`,
options: [4, { MemberExpression: 1, CallExpression: { arguments: 1 } }],
errors: expectedErrors([
[3, 8, 4, "Punctuator"],
[4, 12, 15, "String"],
[5, 12, 14, "Punctuator"],
[6, 16, 14, "Numeric"],
[7, 16, 9, "Numeric"],
[8, 16, 35, "Numeric"],
[9, 12, 22, "Punctuator"],
[10, 8, 0, "Punctuator"],
[11, 0, 1, "Punctuator"]
])
},
// https://github.com/eslint/eslint/issues/7242
{
code: unIndent`
var x = [
[1],
[2]
]
`,
output: unIndent`
var x = [
[1],
[2]
]
`,
errors: expectedErrors([[2, 4, 6, "Punctuator"], [3, 4, 2, "Punctuator"]])
},
{
code: unIndent`
var y = [
{a: 1},
{b: 2}
]
`,
output: unIndent`
var y = [
{a: 1},
{b: 2}
]
`,
errors: expectedErrors([[2, 4, 6, "Punctuator"], [3, 4, 2, "Punctuator"]])
},
{
code: unIndent`
echo = spawn('cmd.exe',
['foo', 'bar',
'baz']);
`,
output: unIndent`
echo = spawn('cmd.exe',
['foo', 'bar',
'baz']);
`,
options: [2, { ArrayExpression: "first", CallExpression: { arguments: "first" } }],
errors: expectedErrors([[2, 13, 12, "Punctuator"], [3, 14, 13, "String"]])
},
{
// https://github.com/eslint/eslint/issues/7522
code: unIndent`
foo(
)
`,
output: unIndent`
foo(
)
`,
errors: expectedErrors([2, 0, 2, "Punctuator"])
},
{
// https://github.com/eslint/eslint/issues/7616
code: unIndent`
foo(
bar,
{
baz: 1
}
)
`,
output: unIndent`
foo(
bar,
{
baz: 1
}
)
`,
options: [4, { CallExpression: { arguments: "first" } }],
errors: expectedErrors([[2, 4, 8, "Identifier"]])
},
{
code: " new Foo",
output: "new Foo",
errors: expectedErrors([1, 0, 2, "Keyword"])
},
{
code: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
}
`,
output: unIndent`
var foo = 0, bar = 0, baz = 0;
export {
foo,
bar,
baz
}
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([[3, 4, 0, "Identifier"], [4, 4, 8, "Identifier"], [5, 4, 2, "Identifier"]])
},
{
code: unIndent`
foo
? bar
: baz
`,
output: unIndent`
foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([3, 4, 0, "Punctuator"])
},
{
code: unIndent`
foo ?
bar :
baz
`,
output: unIndent`
foo ?
bar :
baz
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([3, 4, 0, "Identifier"])
},
{
code: unIndent`
foo ?
bar
: baz
`,
output: unIndent`
foo ?
bar
: baz
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([3, 4, 2, "Punctuator"])
},
{
code: unIndent`
foo
? bar :
baz
`,
output: unIndent`
foo
? bar :
baz
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([3, 4, 0, "Identifier"])
},
{
code: unIndent`
foo ? bar
: baz ? qux
: foobar ? boop
: beep
`,
output: unIndent`
foo ? bar
: baz ? qux
: foobar ? boop
: beep
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([
[3, 4, 8, "Punctuator"],
[4, 4, 12, "Punctuator"]
])
},
{
code: unIndent`
foo ? bar :
baz ? qux :
foobar ? boop :
beep
`,
output: unIndent`
foo ? bar :
baz ? qux :
foobar ? boop :
beep
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([
[3, 4, 8, "Identifier"],
[4, 4, 12, "Identifier"]
])
},
{
code: unIndent`
var a =
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
`,
output: unIndent`
var a =
foo ? bar :
baz ? qux :
foobar ? boop :
/*else*/ beep
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([
[3, 4, 6, "Identifier"],
[4, 4, 2, "Identifier"]
])
},
{
code: unIndent`
var a =
foo
? bar
: baz
`,
output: unIndent`
var a =
foo
? bar
: baz
`,
options: [4, { flatTernaryExpressions: true }],
errors: expectedErrors([
[3, 8, 4, "Punctuator"],
[4, 8, 4, "Punctuator"]
])
},
{
code: unIndent`
foo ? bar
: baz ? qux
: foobar ? boop
: beep
`,
output: unIndent`
foo ? bar
: baz ? qux
: foobar ? boop
: beep
`,
options: [4, { flatTernaryExpressions: false }],
errors: expectedErrors([
[3, 8, 4, "Punctuator"],
[4, 12, 4, "Punctuator"]
])
},
{
code: unIndent`
foo ? bar :
baz ? qux :
foobar ? boop :
beep
`,
output: unIndent`
foo ? bar :
baz ? qux :
foobar ? boop :
beep
`,
options: [4, { flatTernaryExpressions: false }],
errors: expectedErrors([
[3, 8, 4, "Identifier"],
[4, 12, 4, "Identifier"]
])
},
{
code: unIndent`
foo
? bar
: baz
? qux
: foobar
? boop
: beep
`,
output: unIndent`
foo
? bar
: baz
? qux
: foobar
? boop
: beep
`,
options: [4, { flatTernaryExpressions: false }],
errors: expectedErrors([
[4, 8, 4, "Punctuator"],
[5, 8, 4, "Punctuator"],
[6, 12, 4, "Punctuator"],
[7, 12, 4, "Punctuator"]
])
},
{
code: unIndent`
foo ?
bar :
baz ?
qux :
foobar ?
boop :
beep
`,
output: unIndent`
foo ?
bar :
baz ?
qux :
foobar ?
boop :
beep
`,
options: [4, { flatTernaryExpressions: false }],
errors: expectedErrors([
[4, 8, 4, "Identifier"],
[5, 8, 4, "Identifier"],
[6, 12, 4, "Identifier"],
[7, 12, 4, "Identifier"]
])
},
{
code: unIndent`
foo.bar('baz', function(err) {
qux;
});
`,
output: unIndent`
foo.bar('baz', function(err) {
qux;
});
`,
options: [2, { CallExpression: { arguments: "first" } }],
errors: expectedErrors([2, 2, 10, "Identifier"])
},
{
code: unIndent`
foo.bar(function() {
cookies;
}).baz(function() {
cookies;
});
`,
output: unIndent`
foo.bar(function() {
cookies;
}).baz(function() {
cookies;
});
`,
options: [2, { MemberExpression: 1 }],
errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
},
{
code: unIndent`
foo.bar().baz(function() {
cookies;
}).qux(function() {
cookies;
});
`,
output: unIndent`
foo.bar().baz(function() {
cookies;
}).qux(function() {
cookies;
});
`,
options: [2, { MemberExpression: 1 }],
errors: expectedErrors([[4, 2, 4, "Identifier"], [5, 0, 2, "Punctuator"]])
},
{
code: unIndent`
[ foo,
bar ].forEach(function() {
baz;
})
`,
output: unIndent`
[ foo,
bar ].forEach(function() {
baz;
})
`,
options: [2, { ArrayExpression: "first", MemberExpression: 1 }],
errors: expectedErrors([[3, 2, 4, "Identifier"], [4, 0, 2, "Punctuator"]])
},
{
code: unIndent`
foo[
bar
];
`,
output: unIndent`
foo[
bar
];
`,
options: [4, { MemberExpression: 1 }],
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
foo({
bar: 1,
baz: 2
})
`,
output: unIndent`
foo({
bar: 1,
baz: 2
})
`,
options: [4, { ObjectExpression: "first" }],
errors: expectedErrors([[2, 4, 0, "Identifier"], [3, 4, 0, "Identifier"]])
},
{
code: unIndent`
foo(
bar, baz,
qux);
`,
output: unIndent`
foo(
bar, baz,
qux);
`,
options: [2, { CallExpression: { arguments: "first" } }],
errors: expectedErrors([[2, 2, 24, "Identifier"], [3, 2, 24, "Identifier"]])
},
{
code: unIndent`
if (foo) bar()
; [1, 2, 3].map(baz)
`,
output: unIndent`
if (foo) bar()
; [1, 2, 3].map(baz)
`,
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
if (foo)
;
`,
output: unIndent`
if (foo)
;
`,
errors: expectedErrors([2, 4, 0, "Punctuator"])
},
{
code: unIndent`
import {foo}
from 'bar';
`,
output: unIndent`
import {foo}
from 'bar';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([2, 4, 0, "Identifier"])
},
{
code: unIndent`
export {foo}
from 'bar';
`,
output: unIndent`
export {foo}
from 'bar';
`,
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: expectedErrors([2, 4, 0, "Identifier"])
},
{
code: unIndent`
(
a
) => b => {
c
}
`,
output: unIndent`
(
a
) => b => {
c
}
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(
a
) => b => c => d => {
e
}
`,
output: unIndent`
(
a
) => b => c => d => {
e
}
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
if (
foo
) bar(
baz
);
`,
output: unIndent`
if (
foo
) bar(
baz
);
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(
foo
)(
bar
)
`,
output: unIndent`
(
foo
)(
bar
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(() =>
foo
)(
bar
)
`,
output: unIndent`
(() =>
foo
)(
bar
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
(() => {
foo();
})(
bar
)
`,
output: unIndent`
(() => {
foo();
})(
bar
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
foo.
bar.
baz
`,
output: unIndent`
foo.
bar.
baz
`,
errors: expectedErrors([[2, 4, 2, "Identifier"], [3, 4, 6, "Identifier"]])
},
{
code: unIndent`
const foo = a.b(),
longName
= (baz(
'bar',
'bar'
));
`,
output: unIndent`
const foo = a.b(),
longName
= (baz(
'bar',
'bar'
));
`,
errors: expectedErrors([[4, 8, 12, "String"], [5, 8, 12, "String"], [6, 4, 8, "Punctuator"]])
},
{
code: unIndent`
const foo = a.b(),
longName =
(baz(
'bar',
'bar'
));
`,
output: unIndent`
const foo = a.b(),
longName =
(baz(
'bar',
'bar'
));
`,
errors: expectedErrors([[4, 8, 12, "String"], [5, 8, 12, "String"], [6, 4, 8, "Punctuator"]])
},
{
code: unIndent`
const foo = a.b(),
longName
=baz(
'bar',
'bar'
);
`,
output: unIndent`
const foo = a.b(),
longName
=baz(
'bar',
'bar'
);
`,
errors: expectedErrors([[6, 8, 4, "Punctuator"]])
},
{
code: unIndent`
const foo = a.b(),
longName
=(
'fff'
);
`,
output: unIndent`
const foo = a.b(),
longName
=(
'fff'
);
`,
errors: expectedErrors([[4, 12, 8, "String"]])
},
//----------------------------------------------------------------------
// Ignore Unknown Nodes
//----------------------------------------------------------------------
{
code: unIndent`
namespace Foo {
const bar = 3,
baz = 2;
if (true) {
const bax = 3;
}
}
`,
output: unIndent`
namespace Foo {
const bar = 3,
baz = 2;
if (true) {
const bax = 3;
}
}
`,
parser: parser("unknown-nodes/namespace-invalid"),
errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]])
},
{
code: unIndent`
abstract class Foo {
public bar() {
let aaa = 4,
boo;
if (true) {
boo = 3;
}
boo = 3 + 2;
}
}
`,
output: unIndent`
abstract class Foo {
public bar() {
let aaa = 4,
boo;
if (true) {
boo = 3;
}
boo = 3 + 2;
}
}
`,
parser: parser("unknown-nodes/abstract-class-invalid"),
errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]])
},
{
code: unIndent`
function foo() {
function bar() {
abstract class X {
public baz() {
if (true) {
qux();
}
}
}
}
}
`,
output: unIndent`
function foo() {
function bar() {
abstract class X {
public baz() {
if (true) {
qux();
}
}
}
}
}
`,
parser: parser("unknown-nodes/functions-with-abstract-class-invalid"),
errors: expectedErrors([
[4, 12, 8, "Keyword"],
[5, 16, 8, "Keyword"],
[6, 20, 8, "Identifier"],
[7, 16, 8, "Punctuator"],
[8, 12, 8, "Punctuator"]
])
},
{
code: unIndent`
namespace Unknown {
function foo() {
function bar() {
abstract class X {
public baz() {
if (true) {
qux();
}
}
}
}
}
}
`,
output: unIndent`
namespace Unknown {
function foo() {
function bar() {
abstract class X {
public baz() {
if (true) {
qux();
}
}
}
}
}
}
`,
parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"),
errors: expectedErrors([
[3, 8, 4, "Keyword"],
[7, 24, 20, "Identifier"]
])
},
//----------------------------------------------------------------------
// JSX tests
// Some of the following tests are adapted from the tests in eslint-plugin-react.
// License: https://github.com/yannickcr/eslint-plugin-react/blob/7ca9841f22d599f447a27ef5b2a97def9229d6c8/LICENSE
//----------------------------------------------------------------------
{
code: unIndent`
<App>
<Foo />
</App>
`,
output: unIndent`
<App>
<Foo />
</App>
`,
errors: expectedErrors([2, 4, 2, "Punctuator"])
},
{
code: unIndent`
<App>
<Foo />
</App>
`,
output: unIndent`
<App>
<Foo />
</App>
`,
options: [2],
errors: expectedErrors([2, 2, 4, "Punctuator"])
},
{
code: unIndent`
<App>
<Foo />
</App>
`,
output: unIndent`
<App>
\t<Foo />
</App>
`,
options: ["tab"],
errors: expectedErrors([2, "1 tab", "4 spaces", "Punctuator"])
},
{
code: unIndent`
function App() {
return <App>
<Foo />
</App>;
}
`,
output: unIndent`
function App() {
return <App>
<Foo />
</App>;
}
`,
options: [2],
errors: expectedErrors([4, 2, 9, "Punctuator"])
},
{
code: unIndent`
function App() {
return (<App>
<Foo />
</App>);
}
`,
output: unIndent`
function App() {
return (<App>
<Foo />
</App>);
}
`,
options: [2],
errors: expectedErrors([4, 2, 4, "Punctuator"])
},
{
code: unIndent`
function App() {
return (
<App>
<Foo />
</App>
);
}
`,
output: unIndent`
function App() {
return (
<App>
<Foo />
</App>
);
}
`,
options: [2],
errors: expectedErrors([[3, 4, 0, "Punctuator"], [4, 6, 2, "Punctuator"], [5, 4, 0, "Punctuator"]])
},
{
code: unIndent`
<App>
{test}
</App>
`,
output: unIndent`
<App>
{test}
</App>
`,
errors: expectedErrors([2, 4, 1, "Punctuator"])
},
{
code: unIndent`
<App>
{options.map((option, index) => (
<option key={index} value={option.key}>
{option.name}
</option>
))}
</App>
`,
output: unIndent`
<App>
{options.map((option, index) => (
<option key={index} value={option.key}>
{option.name}
</option>
))}
</App>
`,
errors: expectedErrors([4, 12, 11, "Punctuator"])
},
{
code: unIndent`
[
<div />,
<div />
]
`,
output: unIndent`
[
<div />,
<div />
]
`,
options: [2],
errors: expectedErrors([3, 2, 4, "Punctuator"])
},
{
code: unIndent`
<App>
<Foo />
</App>
`,
output: unIndent`
<App>
\t<Foo />
</App>
`,
options: ["tab"],
errors: expectedErrors([3, "1 tab", "1 space", "Punctuator"])
},
{
/*
* Multiline ternary
* (colon at the end of the first expression)
*/
code: unIndent`
foo ?
<Foo /> :
<Bar />
`,
output: unIndent`
foo ?
<Foo /> :
<Bar />
`,
errors: expectedErrors([3, 4, 0, "Punctuator"])
},
{
/*
* Multiline ternary
* (colon on its own line)
*/
code: unIndent`
foo ?
<Foo />
:
<Bar />
`,
output: unIndent`
foo ?
<Foo />
:
<Bar />
`,
errors: expectedErrors([[3, 4, 0, "Punctuator"], [4, 4, 0, "Punctuator"]])
},
{
/*
* Multiline ternary
* (colon at the end of the first expression, parenthesized first expression)
*/
code: unIndent`
foo ? (
<Foo />
) :
<Bar />
`,
output: unIndent`
foo ? (
<Foo />
) :
<Bar />
`,
errors: expectedErrors([4, 4, 0, "Punctuator"])
},
{
code: unIndent`
<App
foo
/>
`,
output: unIndent`
<App
foo
/>
`,
errors: expectedErrors([2, 4, 2, "JSXIdentifier"])
},
{
code: unIndent`
<App
foo
/>
`,
output: unIndent`
<App
foo
/>
`,
options: [2],
errors: expectedErrors([3, 0, 2, "Punctuator"])
},
{
code: unIndent`
<App
foo
></App>
`,
output: unIndent`
<App
foo
></App>
`,
options: [2],
errors: expectedErrors([3, 0, 2, "Punctuator"])
},
{
code: unIndent`
const Button = function(props) {
return (
<Button
size={size}
onClick={onClick}
>
Button Text
</Button>
);
};
`,
output: unIndent`
const Button = function(props) {
return (
<Button
size={size}
onClick={onClick}
>
Button Text
</Button>
);
};
`,
options: [2],
errors: expectedErrors([6, 4, 36, "Punctuator"])
},
{
code: unIndent`
var x = function() {
return <App
foo
/>
}
`,
output: unIndent`
var x = function() {
return <App
foo
/>
}
`,
options: [2],
errors: expectedErrors([4, 2, 9, "Punctuator"])
},
{
code: unIndent`
var x = <App
foo
/>
`,
output: unIndent`
var x = <App
foo
/>
`,
options: [2],
errors: expectedErrors([3, 0, 8, "Punctuator"])
},
{
code: unIndent`
var x = (
<Something
/>
)
`,
output: unIndent`
var x = (
<Something
/>
)
`,
options: [2],
errors: expectedErrors([3, 2, 4, "Punctuator"])
},
{
code: unIndent`
<App
\tfoo
\t/>
`,
output: unIndent`
<App
\tfoo
/>
`,
options: ["tab"],
errors: expectedErrors("tab", [3, 0, 1, "Punctuator"])
},
{
code: unIndent`
<App
\tfoo
\t></App>
`,
output: unIndent`
<App
\tfoo
></App>
`,
options: ["tab"],
errors: expectedErrors("tab", [3, 0, 1, "Punctuator"])
},
{
code: unIndent`
<
foo
.bar
.baz
>
foo
</
foo.
bar.
baz
>
`,
output: unIndent`
<
foo
.bar
.baz
>
foo
</
foo.
bar.
baz
>
`,
errors: expectedErrors([
[3, 8, 4, "Punctuator"],
[4, 8, 4, "Punctuator"],
[9, 8, 4, "JSXIdentifier"],
[10, 8, 4, "JSXIdentifier"]
])
},
{
code: unIndent`
<
input
type=
"number"
/>
`,
output: unIndent`
<
input
type=
"number"
/>
`,
errors: expectedErrors([4, 8, 4, "JSXText"])
},
{
code: unIndent`
<
input
type=
{'number'}
/>
`,
output: unIndent`
<
input
type=
{'number'}
/>
`,
errors: expectedErrors([4, 8, 4, "Punctuator"])
},
{
code: unIndent`
<
input
type
="number"
/>
`,
output: unIndent`
<
input
type
="number"
/>
`,
errors: expectedErrors([4, 8, 4, "Punctuator"])
},
{
code: unIndent`
foo ? (
bar
) : (
baz
)
`,
output: unIndent`
foo ? (
bar
) : (
baz
)
`,
errors: expectedErrors([[4, 4, 8, "Identifier"], [5, 0, 4, "Punctuator"]])
},
{
code: unIndent`
foo ? (
<div>
</div>
) : (
<span>
</span>
)
`,
output: unIndent`
foo ? (
<div>
</div>
) : (
<span>
</span>
)
`,
errors: expectedErrors([[5, 4, 8, "Punctuator"], [6, 4, 8, "Punctuator"], [7, 0, 4, "Punctuator"]])
},
{
code: unIndent`
<div>
{
(
1
)
}
</div>
`,
output: unIndent`
<div>
{
(
1
)
}
</div>
`,
errors: expectedErrors([[3, 8, 4, "Punctuator"], [4, 12, 8, "Numeric"], [5, 8, 4, "Punctuator"]])
},
{
code: unIndent`
<div>
{
/* foo */
}
</div>
`,
output: unIndent`
<div>
{
/* foo */
}
</div>
`,
errors: expectedErrors([3, 8, 6, "Block"])
},
{
code: unIndent`
<div
{...props}
/>
`,
output: unIndent`
<div
{...props}
/>
`,
errors: expectedErrors([2, 4, 0, "Punctuator"])
},
{
code: unIndent`
<div
{
...props
}
/>
`,
output: unIndent`
<div
{
...props
}
/>
`,
errors: expectedErrors([3, 8, 6, "Punctuator"])
},
{
code: unIndent`
<div>foo
<div>bar</div>
</div>
`,
output: unIndent`
<div>foo
<div>bar</div>
</div>
`,
errors: expectedErrors([2, 4, 0, "Punctuator"])
},
{
code: unIndent`
<small>Foo bar
<a>baz qux</a>.
</small>
`,
output: unIndent`
<small>Foo bar
<a>baz qux</a>.
</small>
`,
errors: expectedErrors([2, 4, 0, "Punctuator"])
},
/*
* JSX Fragments
* https://github.com/eslint/eslint/issues/12208
*/
{
code: unIndent`
<>
<A />
</>
`,
output: unIndent`
<>
<A />
</>
`,
errors: expectedErrors([2, 4, 0, "Punctuator"])
},
{
code: unIndent`
<
>
<A />
</>
`,
output: unIndent`
<
>
<A />
</>
`,
errors: expectedErrors([2, 0, 4, "Punctuator"])
},
{
code: unIndent`
<>
<A />
<
/>
`,
output: unIndent`
<>
<A />
<
/>
`,
errors: expectedErrors([4, 0, 4, "Punctuator"])
},
{
code: unIndent`
<>
<A />
</
>
`,
output: unIndent`
<>
<A />
</
>
`,
errors: expectedErrors([4, 0, 4, "Punctuator"])
},
{
code: unIndent`
<
>
<A />
</
>
`,
output: unIndent`
<
>
<A />
</
>
`,
errors: expectedErrors([
[2, 0, 4, "Punctuator"],
[5, 0, 4, "Punctuator"]
])
},
{
code: unIndent`
<
>
<A />
<
/>
`,
output: unIndent`
<
>
<A />
<
/>
`,
errors: expectedErrors([
[2, 0, 4, "Punctuator"],
[5, 0, 4, "Punctuator"]
])
},
{
code: unIndent`
< // Comment
>
<A />
</>
`,
output: unIndent`
< // Comment
>
<A />
</>
`,
errors: expectedErrors([2, 0, 4, "Punctuator"])
},
{
code: unIndent`
<>
<A />
< // Comment
/>
`,
output: unIndent`
<>
<A />
< // Comment
/>
`,
errors: expectedErrors([4, 0, 4, "Punctuator"])
},
{
code: unIndent`
<>
<A />
</ // Comment
>
`,
output: unIndent`
<>
<A />
</ // Comment
>
`,
errors: expectedErrors([4, 0, 4, "Punctuator"])
},
{
code: unIndent`
< /* Comment */
>
<A />
</>
`,
output: unIndent`
< /* Comment */
>
<A />
</>
`,
errors: expectedErrors([2, 0, 4, "Punctuator"])
},
{
code: unIndent`
<>
<A />
< /* Comment */
/>
`,
output: unIndent`
<>
<A />
< /* Comment */
/>
`,
errors: expectedErrors([4, 0, 4, "Punctuator"])
},
{
code: unIndent`
<>
<A />
</ /* Comment */
>
`,
output: unIndent`
<>
<A />
</ /* Comment */
>
`,
errors: expectedErrors([4, 0, 4, "Punctuator"])
},
{
code: unIndent`
({
foo
}: bar) => baz
`,
output: unIndent`
({
foo
}: bar) => baz
`,
parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation"),
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
([
foo
]: bar) => baz
`,
output: unIndent`
([
foo
]: bar) => baz
`,
parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation"),
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
({
foo
}: {}) => baz
`,
output: unIndent`
({
foo
}: {}) => baz
`,
parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation"),
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
class Foo {
foo() {
bar();
}
}
`,
output: unIndent`
class Foo {
foo() {
bar();
}
}
`,
options: [4, { ignoredNodes: ["ClassBody"] }],
errors: expectedErrors([3, 4, 0, "Identifier"])
},
{
code: unIndent`
$(function() {
foo();
bar();
foo(function() {
baz();
});
});
`,
output: unIndent`
$(function() {
foo();
bar();
foo(function() {
baz();
});
});
`,
options: [4, {
ignoredNodes: ["ExpressionStatement > CallExpression[callee.name='$'] > FunctionExpression > BlockStatement"]
}],
errors: expectedErrors([7, 4, 0, "Identifier"])
},
{
code: unIndent`
(function($) {
$(function() {
foo;
});
})()
`,
output: unIndent`
(function($) {
$(function() {
foo;
});
})()
`,
options: [4, {
ignoredNodes: ["ExpressionStatement > CallExpression > FunctionExpression.callee > BlockStatement"]
}],
errors: expectedErrors([3, 4, 0, "Identifier"])
},
{
code: unIndent`
if (foo) {
doSomething();
// Intentionally unindented comment
doSomethingElse();
}
`,
output: unIndent`
if (foo) {
doSomething();
// Intentionally unindented comment
doSomethingElse();
}
`,
options: [4, { ignoreComments: false }],
errors: expectedErrors([4, 4, 0, "Line"])
},
{
code: unIndent`
if (foo) {
doSomething();
/* Intentionally unindented comment */
doSomethingElse();
}
`,
output: unIndent`
if (foo) {
doSomething();
/* Intentionally unindented comment */
doSomethingElse();
}
`,
options: [4, { ignoreComments: false }],
errors: expectedErrors([4, 4, 0, "Block"])
},
{
code: unIndent`
const obj = {
foo () {
return condition ? // comment
1 :
2
}
}
`,
output: unIndent`
const obj = {
foo () {
return condition ? // comment
1 :
2
}
}
`,
errors: expectedErrors([4, 12, 8, "Numeric"])
},
//----------------------------------------------------------------------
// Comment alignment tests
//----------------------------------------------------------------------
{
code: unIndent`
if (foo) {
// Comment cannot align with code immediately above if there is a whitespace gap
doSomething();
}
`,
output: unIndent`
if (foo) {
// Comment cannot align with code immediately above if there is a whitespace gap
doSomething();
}
`,
errors: expectedErrors([3, 4, 0, "Line"])
},
{
code: unIndent`
if (foo) {
foo(
bar);
// Comment cannot align with code immediately below if there is a whitespace gap
}
`,
output: unIndent`
if (foo) {
foo(
bar);
// Comment cannot align with code immediately below if there is a whitespace gap
}
`,
errors: expectedErrors([4, 4, 0, "Line"])
},
{
code: unIndent`
[{
foo
},
// Comment between nodes
{
bar
}];
`,
output: unIndent`
[{
foo
},
// Comment between nodes
{
bar
}];
`,
errors: expectedErrors([5, 0, 4, "Line"])
},
{
code: unIndent`
let foo
// comment
;(async () => {})()
`,
output: unIndent`
let foo
// comment
;(async () => {})()
`,
errors: expectedErrors([3, 0, 4, "Line"])
},
{
code: unIndent`
let foo
// comment
;(async () => {})()
`,
output: unIndent`
let foo
// comment
;(async () => {})()
`,
errors: expectedErrors([2, 0, 4, "Line"])
},
{
code: unIndent`
let foo
/* comment */;
(async () => {})()
`,
output: unIndent`
let foo
/* comment */;
(async () => {})()
`,
errors: expectedErrors([3, 4, 0, "Block"])
},
{
code: unIndent`
// comment
;(async () => {})()
`,
output: unIndent`
// comment
;(async () => {})()
`,
errors: expectedErrors([1, 0, 4, "Line"])
},
{
code: unIndent`
// comment
;(async () => {})()
`,
output: unIndent`
// comment
;(async () => {})()
`,
errors: expectedErrors([1, 0, 4, "Line"])
},
{
code: unIndent`
{
let foo
// comment
;(async () => {})()
}
`,
output: unIndent`
{
let foo
// comment
;(async () => {})()
}
`,
errors: expectedErrors([4, 4, 8, "Line"])
},
{
code: unIndent`
{
let foo
// comment
;(async () => {})()
}
`,
output: unIndent`
{
let foo
// comment
;(async () => {})()
}
`,
errors: expectedErrors([3, 4, 8, "Line"])
},
{
code: unIndent`
{
let foo
/* comment */;
(async () => {})()
}
`,
output: unIndent`
{
let foo
/* comment */;
(async () => {})()
}
`,
errors: expectedErrors([4, 8, 4, "Block"])
},
{
code: unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
output: unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
errors: expectedErrors([4, 0, 4, "Block"])
},
{
code: unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
output: unIndent`
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
`,
errors: expectedErrors([3, 0, 4, "Block"])
},
{
code: unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
output: unIndent`
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
`,
errors: expectedErrors([4, 4, 0, "Block"])
},
{
code: unIndent`
/* comment */
;[1, 2, 3].forEach(() => {})
`,
output: unIndent`
/* comment */
;[1, 2, 3].forEach(() => {})
`,
errors: expectedErrors([1, 0, 4, "Block"])
},
{
code: unIndent`
/* comment */
;[1, 2, 3].forEach(() => {})
`,
output: unIndent`
/* comment */
;[1, 2, 3].forEach(() => {})
`,
errors: expectedErrors([1, 0, 4, "Block"])
},
{
code: unIndent`
{
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
output: unIndent`
{
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
errors: expectedErrors([5, 4, 8, "Block"])
},
{
code: unIndent`
{
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
output: unIndent`
{
const foo = 1
const bar = foo
/* comment */
;[1, 2, 3].forEach(() => {})
}
`,
errors: expectedErrors([4, 4, 8, "Block"])
},
{
code: unIndent`
{
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
}
`,
output: unIndent`
{
const foo = 1
const bar = foo
/* comment */;
[1, 2, 3].forEach(() => {})
}
`,
errors: expectedErrors([5, 8, 4, "Block"])
},
// import expressions
{
code: unIndent`
import(
source
)
`,
output: unIndent`
import(
source
)
`,
parserOptions: { ecmaVersion: 2020 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 0, 4, "Punctuator"]
])
},
// https://github.com/eslint/eslint/issues/12122
{
code: unIndent`
foo(() => {
tag\`
multiline
template\${a} \${b}
literal
\`(() => {
bar();
});
});
`,
output: unIndent`
foo(() => {
tag\`
multiline
template\${a} \${b}
literal
\`(() => {
bar();
});
});
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[7, 8, 4, "Identifier"]
])
},
{
code: unIndent`
{
tag\`
multiline
template
literal
\${a} \${b}\`(() => {
bar();
});
}
`,
output: unIndent`
{
tag\`
multiline
template
literal
\${a} \${b}\`(() => {
bar();
});
}
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[2, 4, 8, "Identifier"],
[7, 8, 12, "Identifier"],
[8, 4, 8, "Punctuator"]
])
},
{
code: unIndent`
foo(() => {
tagOne\`\${a} \${b}
multiline
template
literal
\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
});
`,
output: unIndent`
foo(() => {
tagOne\`\${a} \${b}
multiline
template
literal
\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
});
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[7, 8, 12, "Identifier"],
[15, 8, 12, "Identifier"],
[16, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
{
tagOne\`
multiline
template
literal
\${a} \${b}\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
}
`,
output: unIndent`
{
tagOne\`
multiline
template
literal
\${a} \${b}\`(() => {
tagTwo\`
multiline
template
literal
\`(() => {
bar();
});
baz();
});
}
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[7, 8, 12, "Identifier"],
[15, 8, 12, "Identifier"],
[16, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
tagOne\`multiline \${a} \${b}
template
literal
\`(() => {
foo();
tagTwo\`multiline
template
literal
\`({
bar: 1,
baz: 2
});
});
`,
output: unIndent`
tagOne\`multiline \${a} \${b}
template
literal
\`(() => {
foo();
tagTwo\`multiline
template
literal
\`({
bar: 1,
baz: 2
});
});
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[5, 4, 0, "Identifier"],
[11, 8, 4, "Identifier"]
])
},
{
code: unIndent`
tagOne\`multiline
template \${a} \${b}
literal\`({
foo: 1,
bar: tagTwo\`multiline
template
literal\`(() => {
baz();
})
});
`,
output: unIndent`
tagOne\`multiline
template \${a} \${b}
literal\`({
foo: 1,
bar: tagTwo\`multiline
template
literal\`(() => {
baz();
})
});
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[4, 4, 8, "Identifier"],
[5, 4, 0, "Identifier"],
[9, 8, 0, "Identifier"]
])
},
{
code: unIndent`
foo.bar\` template literal \`(() => {
baz();
})
`,
output: unIndent`
foo.bar\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[2, 4, 8, "Identifier"]
])
},
{
code: unIndent`
foo.bar.baz\` template literal \`(() => {
baz();
})
`,
output: unIndent`
foo.bar.baz\` template literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 0, 4, "Punctuator"]
])
},
{
code: unIndent`
foo
.bar\` template
literal \`(() => {
baz();
})
`,
output: unIndent`
foo
.bar\` template
literal \`(() => {
baz();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
bar();
})
`,
output: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
bar();
})
`,
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[5, 8, 0, "Identifier"]
])
},
{
code: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
bar();
})
`,
output: unIndent`
foo
.test\`
\${a} \${b}
\`(() => {
bar();
})
`,
options: [4, { MemberExpression: 0 }],
parserOptions: { ecmaVersion: 2015 },
errors: expectedErrors([
[2, 0, 4, "Punctuator"],
[5, 4, 0, "Identifier"],
[6, 0, 4, "Punctuator"]
])
},
// Optional chaining
{
code: unIndent`
obj
?.prop
?.[key]
?.
[key]
`,
output: unIndent`
obj
?.prop
?.[key]
?.
[key]
`,
options: [4],
parserOptions: { ecmaVersion: 2020 },
errors: expectedErrors([
[2, 4, 0, "Punctuator"],
[3, 4, 0, "Punctuator"],
[4, 4, 0, "Punctuator"],
[5, 8, 0, "Punctuator"]
])
},
{
code: unIndent`
(
longSomething
?.prop
?.[key]
)
?.prop
?.[key]
`,
output: unIndent`
(
longSomething
?.prop
?.[key]
)
?.prop
?.[key]
`,
options: [4],
parserOptions: { ecmaVersion: 2020 },
errors: expectedErrors([
[6, 4, 0, "Punctuator"],
[7, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
obj
?.(arg)
?.
(arg)
`,
output: unIndent`
obj
?.(arg)
?.
(arg)
`,
options: [4],
parserOptions: { ecmaVersion: 2020 },
errors: expectedErrors([
[2, 4, 0, "Punctuator"],
[3, 4, 0, "Punctuator"],
[4, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
(
longSomething
?.(arg)
?.(arg)
)
?.(arg)
?.(arg)
`,
output: unIndent`
(
longSomething
?.(arg)
?.(arg)
)
?.(arg)
?.(arg)
`,
options: [4],
parserOptions: { ecmaVersion: 2020 },
errors: expectedErrors([
[6, 4, 0, "Punctuator"],
[7, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
const foo = async (arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
output: unIndent`
const foo = async (arg1,
arg2) =>
{
return arg1 + arg2;
}
`,
options: [2, { FunctionDeclaration: { parameters: "first" }, FunctionExpression: { parameters: "first" } }],
parserOptions: { ecmaVersion: 2020 },
errors: expectedErrors([
[2, 19, 20, "Identifier"]
])
},
{
code: unIndent`
const a = async
b => {}
`,
output: unIndent`
const a = async
b => {}
`,
options: [2],
errors: expectedErrors([
[2, 0, 1, "Identifier"]
])
},
{
code: unIndent`
class C {
field1;
static field2;
}
`,
output: unIndent`
class C {
field1;
static field2;
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 4, 0, "Keyword"]
])
},
{
code: unIndent`
class C {
field1
=
0
;
static
field2
=
0
;
}
`,
output: unIndent`
class C {
field1
=
0
;
static
field2
=
0
;
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 8, 0, "Punctuator"],
[4, 12, 0, "Numeric"],
[5, 12, 0, "Punctuator"],
[6, 4, 0, "Keyword"],
[7, 8, 0, "Identifier"],
[8, 12, 0, "Punctuator"],
[9, 16, 0, "Numeric"],
[10, 16, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
[
field1
]
=
0
;
static
[
field2
]
=
0
;
[
field3
] =
0;
[field4] =
0;
}
`,
output: unIndent`
class C {
[
field1
]
=
0
;
static
[
field2
]
=
0
;
[
field3
] =
0;
[field4] =
0;
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Punctuator"],
[3, 8, 0, "Identifier"],
[4, 4, 0, "Punctuator"],
[5, 8, 0, "Punctuator"],
[6, 12, 0, "Numeric"],
[7, 12, 0, "Punctuator"],
[8, 4, 0, "Keyword"],
[9, 4, 0, "Punctuator"],
[10, 8, 0, "Identifier"],
[11, 4, 0, "Punctuator"],
[12, 8, 0, "Punctuator"],
[13, 12, 0, "Numeric"],
[14, 12, 0, "Punctuator"],
[15, 4, 0, "Punctuator"],
[16, 8, 0, "Identifier"],
[17, 4, 0, "Punctuator"],
[18, 8, 0, "Numeric"],
[19, 4, 0, "Punctuator"],
[20, 8, 0, "Numeric"]
])
},
{
code: unIndent`
class C {
field1 = (
foo
+ bar
);
}
`,
output: unIndent`
class C {
field1 = (
foo
+ bar
);
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 8, 0, "Identifier"],
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
#aaa
foo() {
return this.#aaa
}
}
`,
output: unIndent`
class C {
#aaa
foo() {
return this.#aaa
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "PrivateIdentifier"],
[3, 4, 0, "Identifier"],
[4, 8, 0, "Keyword"],
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [2],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 2, 0, "Keyword"],
[3, 4, 0, "Identifier"],
[4, 4, 0, "Identifier"],
[5, 2, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 8, 0, "Identifier"],
[4, 8, 0, "Identifier"],
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 8, "Keyword"],
[3, 8, 4, "Identifier"],
[4, 8, 0, "Identifier"],
[5, 4, 8, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4, { StaticBlock: { body: 2 } }],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 12, 0, "Identifier"],
[4, 12, 0, "Identifier"],
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
static {
foo();
bar();
}
}
`,
options: [4, { StaticBlock: { body: 0 } }],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 4, 0, "Identifier"],
[4, 4, 0, "Identifier"],
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
\tstatic {
\t\tfoo();
\t\tbar();
\t}
}
`,
options: ["tab"],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors("tab", [
[2, 1, 0, "Keyword"],
[3, 2, 0, "Identifier"],
[4, 2, 0, "Identifier"],
[5, 1, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo();
bar();
}
}
`,
output: unIndent`
class C {
\tstatic {
\t\t\tfoo();
\t\t\tbar();
\t}
}
`,
options: ["tab", { StaticBlock: { body: 2 } }],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors("tab", [
[2, 1, 0, "Keyword"],
[3, 3, 0, "Identifier"],
[4, 3, 0, "Identifier"],
[5, 1, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static
{
foo();
bar();
}
}
`,
output: unIndent`
class C {
static
{
foo();
bar();
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 4, 0, "Punctuator"],
[4, 8, 0, "Identifier"],
[5, 8, 0, "Identifier"],
[6, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static
{
foo();
bar();
}
}
`,
output: unIndent`
class C {
static
{
foo();
bar();
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[3, 4, 8, "Punctuator"],
[6, 4, 8, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
var x,
y;
}
}
`,
output: unIndent`
class C {
static {
var x,
y;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 8, 0, "Keyword"],
[4, 12, 0, "Identifier"],
[5, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static
{
var x,
y;
}
}
`,
output: unIndent`
class C {
static
{
var x,
y;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 4, 0, "Punctuator"],
[4, 8, 0, "Keyword"],
[5, 12, 0, "Identifier"],
[6, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
if (foo) {
bar;
}
}
}
`,
output: unIndent`
class C {
static {
if (foo) {
bar;
}
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 8, 0, "Keyword"],
[4, 12, 0, "Identifier"],
[5, 8, 0, "Punctuator"],
[6, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
{
bar;
}
}
}
`,
output: unIndent`
class C {
static {
{
bar;
}
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 8, 0, "Punctuator"],
[4, 12, 0, "Identifier"],
[5, 8, 0, "Punctuator"],
[6, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {}
static {
}
static
{
}
}
`,
output: unIndent`
class C {
static {}
static {
}
static
{
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[4, 4, 0, "Keyword"],
[5, 4, 0, "Punctuator"],
[7, 4, 0, "Keyword"],
[8, 4, 0, "Punctuator"],
[9, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
static {
foo;
}
static {
bar;
}
}
`,
output: unIndent`
class C {
static {
foo;
}
static {
bar;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[3, 4, 0, "Keyword"],
[4, 8, 4, "Identifier"],
[5, 4, 0, "Punctuator"],
[7, 4, 0, "Keyword"],
[8, 8, 4, "Identifier"],
[9, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
x = 1;
static {
foo;
}
y = 2;
}
`,
output: unIndent`
class C {
x = 1;
static {
foo;
}
y = 2;
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[3, 4, 0, "Identifier"],
[5, 4, 0, "Keyword"],
[6, 8, 4, "Identifier"],
[7, 4, 0, "Punctuator"],
[9, 4, 0, "Identifier"]
])
},
{
code: unIndent`
class C {
method1(param) {
foo;
}
static {
bar;
}
method2(param) {
foo;
}
}
`,
output: unIndent`
class C {
method1(param) {
foo;
}
static {
bar;
}
method2(param) {
foo;
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[3, 4, 0, "Identifier"],
[4, 8, 4, "Identifier"],
[5, 4, 0, "Punctuator"],
[7, 4, 0, "Keyword"],
[8, 8, 4, "Identifier"],
[9, 4, 0, "Punctuator"],
[11, 4, 0, "Identifier"],
[12, 8, 4, "Identifier"],
[13, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
function f() {
class C {
static {
foo();
bar();
}
}
}
`,
output: unIndent`
function f() {
class C {
static {
foo();
bar();
}
}
}
`,
options: [4],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Keyword"],
[3, 8, 0, "Keyword"],
[4, 12, 0, "Identifier"],
[5, 12, 0, "Identifier"],
[6, 8, 0, "Punctuator"],
[7, 4, 0, "Punctuator"]
])
},
{
code: unIndent`
class C {
method() {
foo;
}
static {
bar;
}
}
`,
output: unIndent`
class C {
method() {
foo;
}
static {
bar;
}
}
`,
options: [4, { FunctionExpression: { body: 2 }, StaticBlock: { body: 2 } }],
parserOptions: { ecmaVersion: 2022 },
errors: expectedErrors([
[2, 4, 0, "Identifier"],
[3, 12, 0, "Identifier"],
[4, 4, 0, "Punctuator"],
[5, 4, 0, "Keyword"],
[6, 12, 0, "Identifier"],
[7, 4, 0, "Punctuator"]
])
}
]
});
|
src/docs/Docs.js
|
thomashoggard/ps-react-tom
|
import React from 'react';
import Navigation from './Navigation';
import ComponentPage from './ComponentPage';
import componentData from '../../config/componentData';
export default class Docs extends React.Component {
constructor(props) {
super(props);
this.state = {
route: window.location.hash.substr(1)
};
}
componentDidMount() {
window.addEventListener('hashchange', () => {
this.setState({route: window.location.hash.substr(1)})
})
}
render() {
const {route} = this.state;
const component = route ? componentData.filter( component => component.name === route)[0] : componentData[0];
return (
<div>
<Navigation components={componentData.map(component => component.name)} />
<ComponentPage component={component} />
</div>
)
}
}
|
Examples/src/components/InputExamples.js
|
sitb-software/ReactNativeComponents
|
import React from 'react';
import { View } from 'react-native';
import AbstractComponent from './AbstractComponent';
import Input from 'react-native-components/form/Input';
import Button from 'react-native-components/bootstrap/Button';
let dataSource = [
{
placeholder: 'Default Input',
},
{
placeholder: 'Custom Style',
style: {
height: 30,
borderRadius: 5,
},
},
{
placeholder: 'Icon Input',
before: 'user',
after: 'plus',
style: {
height: 30,
borderRadius: 5,
},
},
{
placeholder: 'Input with Button',
after: (
<Button
beforeIcon="search"
bsStyle="link"
style={{ justifyContent: 'center', alignItems: 'center', width: 30 }}
/>
),
},
{
placeholder: 'secureTextEntry',
secureTextEntry: true,
},
];
/**
* @author 田尘殇Sean(sean.snow@live.com)
* @date 16/5/5
*/
class InputExamples extends AbstractComponent {
constructor(props) {
super(props, dataSource);
}
renderRow(input) {
return (
<View style={{ marginTop: 10 }}>
<Input {...input} />
</View>
);
}
}
export default InputExamples;
|
src/components/sourcetree/original/SourcetreeOriginal.js
|
fpoumian/react-devicon
|
import React from 'react'
import PropTypes from 'prop-types'
import SVGDeviconInline from '../../_base/SVGDeviconInline'
import iconSVG from './SourcetreeOriginal.svg'
/** SourcetreeOriginal */
function SourcetreeOriginal({ width, height, className }) {
return (
<SVGDeviconInline
className={'SourcetreeOriginal' + ' ' + className}
iconSVG={iconSVG}
width={width}
height={height}
/>
)
}
SourcetreeOriginal.propTypes = {
className: PropTypes.string,
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}
export default SourcetreeOriginal
|
src/index.js
|
ambershen/ambershen.github.io
|
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import App from './components/App';
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root'),
);
|
src/SplitButton.js
|
JimiHFord/react-bootstrap
|
import React from 'react';
import BootstrapMixin from './BootstrapMixin';
import Button from './Button';
import Dropdown from './Dropdown';
import SplitToggle from './SplitToggle';
class SplitButton extends React.Component {
render() {
let {
children,
title,
onClick,
target,
href,
// bsStyle is validated by 'Button' component
bsStyle, // eslint-disable-line
...props } = this.props;
let { disabled } = props;
let button = (
<Button
onClick={onClick}
bsStyle={bsStyle}
disabled={disabled}
target={target}
href={href}
>
{title}
</Button>
);
return (
<Dropdown {...props}>
{button}
<SplitToggle
aria-label={title}
bsStyle={bsStyle}
disabled={disabled}
/>
<Dropdown.Menu>
{children}
</Dropdown.Menu>
</Dropdown>
);
}
}
SplitButton.propTypes = {
...Dropdown.propTypes,
...BootstrapMixin.propTypes,
/**
* @private
*/
onClick() {},
target: React.PropTypes.string,
href: React.PropTypes.string,
/**
* The content of the split button.
*/
title: React.PropTypes.node.isRequired
};
SplitButton.defaultProps = {
disabled: false,
dropup: false,
pullRight: false
};
SplitButton.Toggle = SplitToggle;
export default SplitButton;
|
src/components/widgets/RichTextEditorToolbox.js
|
rsamec/react-designer
|
import React from 'react';
import _ from 'lodash';
const TooltipStyle = {
position: 'absolute',
padding: '0 5px'
};
const TooltipInnerStyle = {
padding: '3px 8px',
color: '#fff',
textAlign: 'center',
borderRadius: 3,
backgroundColor: '#000',
opacity: .75
};
const TooltipArrowStyle = {
position: 'absolute',
width: 0, height: 0,
borderRightColor: 'transparent',
borderLeftColor: 'transparent',
borderTopColor: 'transparent',
borderBottomColor: 'transparent',
borderStyle: 'solid',
opacity: .75
};
const PlacementStyles = {
left: {
tooltip: {marginLeft: -3, padding: '0 5px'},
arrow: {
right: 0, marginTop: -5, borderWidth: '5px 0 5px 5px', borderLeftColor: '#000'
}
},
right: {
tooltip: {marginRight: 3, padding: '0 5px'},
arrow: {left: 0, marginTop: -5, borderWidth: '5px 5px 5px 0', borderRightColor: '#000'}
},
top: {
tooltip: {marginTop: -3, padding: '5px 0'},
arrow: {bottom: 0, marginLeft: -5, borderWidth: '5px 5px 0', borderTopColor: '#000'}
},
bottom: {
tooltip: {marginBottom: 3, padding: '5px 0'},
arrow: {top: 0, marginLeft: -5, borderWidth: '0 5px 5px', borderBottomColor: '#000'}
}
};
export default class ToolTip extends React.Component {
render() {
let placementStyle = PlacementStyles[this.props.placement];
let {
style,
arrowOffsetLeft: left = placementStyle.arrow.left,
arrowOffsetTop: top = placementStyle.arrow.top} = this.props;
let tooltipStyle = _.extend({},TooltipStyle,placementStyle.tooltip,style);
let tooltipArrowStyle = _.extend({},TooltipArrowStyle,placementStyle.arrow,{left:left,top:top});
return (
<div style={tooltipStyle}>
<div style={tooltipArrowStyle}/>
<div style={TooltipInnerStyle}>
{ this.props.children }
</div>
</div>
);
}
}
|
src/main.js
|
denn1s/nanoreno
|
import 'babel-polyfill'
import 'whatwg-fetch'
import React from 'react'
import ReactDOM from 'react-dom'
import FastClick from 'fastclick'
import { Provider } from 'react-redux'
import store from './store'
import history from './history'
import Scene from './Scene'
import Start from './Start'
import Credits from './Credits'
import MainGame from './MainGame'
// let routes = require('./scenes.json').default
const container = document.getElementById('container')
function renderComponent(component) {
ReactDOM.render(<Provider store={store}>{component}</Provider>, container)
}
function render(location) {
console.log(location.pathname)
return renderComponent(<MainGame />)
// router.resolve(routes, location)
// .then(renderComponent)
// .catch(error => router.resolve(routes, { ...location, error }).then(renderComponent))
}
history.listen(render)
render(history.location)
FastClick.attach(document.body)
/*
if (module.hot) {
module.hot.accept('./scenes.json', () => {
routes = require('./scenes.json').default
render(history.location)
})
}
*/
|
src/components/board/Table.js
|
josephquested/plainscreen
|
import React from 'react'
import Row from './Row'
import Cell from './Cell'
export default React.createClass({
generateTable: function () {
let rows = new Array(Number(this.props.height)).fill()
rows = rows.map((row, index) => {
return <Row gameState={this.props.gameState}
id={index} width={this.props.width}
key={index}/>
})
return (
<tbody>
{rows}
</tbody>
)
},
render () {
return (
<table id={this.props.id}>
{this.generateTable()}
</table>
)
}
})
|
geonode/monitoring/frontend/monitoring/src/components/organisms/ws-analytics/index.js
|
francbartoli/geonode
|
/*
#########################################################################
#
# Copyright (C) 2019 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
*/
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import HoverPaper from '../../atoms/hover-paper';
import HR from '../../atoms/hr';
import WSServiceSelect from '../../molecules/ws-service-select';
import ResponseTime from '../../cels/response-time';
import Throughput from '../../cels/throughput';
import ErrorsRate from '../../cels/errors-rate';
import { getCount, getTime } from '../../../utils';
import styles from './styles';
import actions from './actions';
const mapStateToProps = (state) => ({
errors: state.wsErrorSequence.response,
interval: state.interval.interval,
responseTimes: state.wsServiceData.response,
responses: state.wsResponseSequence.response,
selected: state.wsService.service,
throughputs: state.wsThroughputSequence.throughput,
timestamp: state.interval.timestamp,
});
@connect(mapStateToProps, actions)
class WSAnalytics extends React.Component {
static propTypes = {
errors: PropTypes.object,
getErrors: PropTypes.func.isRequired,
getResponseTimes: PropTypes.func.isRequired,
getResponses: PropTypes.func.isRequired,
getThroughputs: PropTypes.func.isRequired,
interval: PropTypes.number,
resetErrors: PropTypes.func.isRequired,
resetResponseTimes: PropTypes.func.isRequired,
resetResponses: PropTypes.func.isRequired,
resetThroughputs: PropTypes.func.isRequired,
responseTimes: PropTypes.object,
responses: PropTypes.object,
selected: PropTypes.string,
throughputs: PropTypes.object,
timestamp: PropTypes.instanceOf(Date),
}
constructor(props) {
super(props);
this.get = (
service = this.props.selected,
interval = this.props.interval,
) => {
this.props.getResponses(service, interval);
this.props.getResponseTimes(service, interval);
this.props.getThroughputs(service, interval);
this.props.getErrors(service, interval);
};
this.reset = () => {
this.props.resetResponses();
this.props.resetResponseTimes();
this.props.resetThroughputs();
this.props.resetErrors();
};
}
componentWillMount() {
if (this.props.timestamp && this.props.selected) {
this.get();
}
}
componentWillReceiveProps(nextProps) {
if (nextProps && nextProps.selected && nextProps.timestamp) {
if ((nextProps.timestamp !== this.props.timestamp) ||
(nextProps.selected !== this.props.selected)) {
this.get(nextProps.selected, nextProps.interval);
}
}
}
componentWillUnmount() {
this.reset();
}
render() {
let responseData = [];
let throughputData = [];
let errorRateData = [];
let averageResponseTime = 0;
let maxResponseTime = 0;
if (this.props.responseTimes) {
const data = this.props.responseTimes.data.data;
if (data.length > 0) {
if (data[0].data.length > 0) {
const metric = data[0].data[0];
maxResponseTime = Math.floor(metric.max);
averageResponseTime = Math.floor(metric.val);
}
}
}
responseData = getTime(this.props.responses);
throughputData = getCount(this.props.throughputs);
errorRateData = getCount(this.props.errors);
return (
<HoverPaper style={styles.content}>
<h3>W*S Analytics</h3>
<WSServiceSelect />
<ResponseTime
average={averageResponseTime}
max={maxResponseTime}
data={responseData}
/>
<HR />
<Throughput data={throughputData} />
<HR />
<ErrorsRate data={errorRateData} />
</HoverPaper>
);
}
}
export default WSAnalytics;
|
packages/type/examples/styled-components/src/App.js
|
carbon-design-system/carbon-components
|
import { display04 } from '@carbon/type';
import React, { Component } from 'react';
import styled from 'styled-components';
import logo from './logo.svg';
import './App.css';
const Title = styled.h1(display04);
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Title>
Hello world!{' '}
<span aria-label="waving" role="img">
👋
</span>
</Title>
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer">
Learn React
</a>
</header>
</div>
);
}
}
export default App;
|
docs/src/app/pages/components/PanelGroup/ExamplePanelGroupMultiStep.js
|
GetAmbassador/react-ions
|
import React from 'react'
import {PanelGroup, Panel, PanelHeader, PanelContent} from 'react-ions/lib/components/PanelGroup'
import Badge from 'react-ions/lib/components/Badge'
import style from './style.scss'
const content = {
lorum1: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vehicula finibus purus, in ultrices mi ullamcorper in. Vestibulum porta varius sem, eu consectetur dui. Aliquam erat volutpat. Aliquam fringilla ullamcorper faucibus. Praesent purus lacus, interdum ac augue in, accumsan lacinia lorem. Nam pharetra lacus nisl, quis sagittis justo scelerisque ac. Phasellus euismod risus sit amet quam finibus, id sodales lectus scelerisque. Sed rhoncus magna neque, sed vulputate augue lobortis pharetra. Praesent placerat dui vitae fermentum tristique. Ut lobortis lacus scelerisque justo porta, quis porta nunc faucibus. Mauris ornare sem vel ornare ullamcorper. Nam tincidunt lacus ut varius faucibus. Maecenas varius lacus eget nisl condimentum, sed commodo justo euismod. Curabitur at justo quam.',
lorum2: 'Sed rhoncus magna neque, sed vulputate augue lobortis pharetra. Praesent placerat dui vitae fermentum tristique.',
lorum3: 'Ut lobortis lacus scelerisque justo porta, quis porta nunc faucibus. Mauris ornare sem vel ornare ullamcorper. Nam tincidunt lacus ut varius faucibus. Maecenas varius lacus eget nisl condimentum, sed commodo justo euismod. Curabitur at justo quam.',
lorum4: 'Maecenas sit amet tellus vitae nisl gravida consectetur in vitae nibh. Quisque bibendum consectetur sagittis. Cras nec mauris maximus, egestas magna eget, vehicula ligula. Duis vestibulum leo at nisl placerat, euismod posuere ante accumsan. Vivamus gravida velit eu accumsan vulputate. Maecenas risus neque, mollis mollis est sit amet, porta feugiat nisi. Praesent maximus ut ante vel aliquet. Nunc mattis pharetra tellus, non volutpat lorem. Vestibulum odio arcu, laoreet a mi non, bibendum eleifend lorem. Nunc turpis lectus, malesuada id augue non, lacinia tristique orci. In fermentum, nibh id venenatis iaculis, lorem ipsum faucibus enim, vitae tincidunt lorem nunc eu tortor. Vestibulum gravida augue risus, non rhoncus velit feugiat vel. Vestibulum imperdiet velit a ligula eleifend rutrum. Vestibulum consequat, arcu sed aliquam pretium, metus metus consectetur lectus, in rutrum tellus metus a felis. Praesent lacus justo, pretium ac lacinia eu, luctus quis nisl.'
}
const ExamplePanelGroupMultiStep = () => (
<div>
<PanelGroup accordion={true} optClass='multi-step'>
<Panel>
<PanelHeader title='What will your survey look like for each channel?' contextNode={<Badge text='1' />} toggleIcon={{name: 'md-keyboard-down', size: '14'}} />
<PanelContent optClass={style['rating-specific']}>
<p className={style.paragraph}>{content.lorum1}</p>
</PanelContent>
</Panel>
<Panel>
<PanelHeader title='What happens after a user submits their response?' contextNode={<Badge text='2' />} toggleIcon={{name: 'md-keyboard-down', size: '14'}} />
<PanelContent>
<p className={style.paragraph}>{content.lorum2}</p>
</PanelContent>
</Panel>
<Panel>
<PanelHeader title='Who should we send this survey to?' contextNode={<Badge text='3' />} toggleIcon={{name: 'md-keyboard-down', size: '14'}} />
<PanelContent>
<p className={style.paragraph}>{content.lorum3}</p>
</PanelContent>
</Panel>
<Panel>
<PanelHeader title='Who should we not send this survey to?' contextNode={<Badge text='4' />} toggleIcon={{name: 'md-keyboard-down', size: '14'}} />
<PanelContent>
<p className={style.paragraph}>{content.lorum4}</p>
</PanelContent>
</Panel>
<Panel>
<PanelHeader title='Where should we send survey notifications?' contextNode={<Badge text='5' />} toggleIcon={{name: 'md-keyboard-down', size: '14'}} />
<PanelContent>
<p className={style.paragraph}>{content.lorum1}</p>
</PanelContent>
</Panel>
</PanelGroup>
</div>
)
export default ExamplePanelGroupMultiStep
|
node_modules/@material-ui/styles/esm/styled/styled.js
|
pcclarke/civ-techs
|
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import React from 'react';
import clsx from 'clsx';
import warning from 'warning';
import PropTypes from 'prop-types';
import { chainPropTypes, getDisplayName } from '@material-ui/utils';
import hoistNonReactStatics from 'hoist-non-react-statics';
import makeStyles from '../makeStyles';
function omit(input, fields) {
var output = {};
Object.keys(input).forEach(function (prop) {
if (fields.indexOf(prop) === -1) {
output[prop] = input[prop];
}
});
return output;
} // styled-components's API removes the mapping between components and styles.
// Using components as a low-level styling construct can be simpler.
function styled(Component) {
var componentCreator = function componentCreator(style) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var name = options.name,
stylesOptions = _objectWithoutProperties(options, ["name"]);
if (process.env.NODE_ENV !== 'production' && Component === undefined) {
throw new Error(['You are calling styled(Component)(style) with an undefined component.', 'You may have forgotten to import it.'].join('\n'));
}
var classNamePrefix = name;
if (process.env.NODE_ENV !== 'production' && !name) {
// Provide a better DX outside production.
classNamePrefix = getDisplayName(Component);
process.env.NODE_ENV !== "production" ? warning(typeof classNamePrefix === 'string', ['Material-UI: the component displayName is invalid. It needs to be a string.', "Please fix the following component: ".concat(Component, ".")].join('\n')) : void 0;
}
var stylesOrCreator = typeof style === 'function' ? function (theme) {
return {
root: function root(props) {
return style(_extends({
theme: theme
}, props));
}
};
} : {
root: style
};
var useStyles = makeStyles(stylesOrCreator, _extends({
Component: Component,
name: name || Component.displayName,
classNamePrefix: classNamePrefix
}, stylesOptions));
var filterProps;
var propTypes = {};
if (style.filterProps) {
filterProps = style.filterProps;
delete style.filterProps;
}
/* eslint-disable react/forbid-foreign-prop-types */
if (style.propTypes) {
propTypes = style.propTypes;
delete style.propTypes;
}
/* eslint-enable react/forbid-foreign-prop-types */
var StyledComponent = React.forwardRef(function StyledComponent(props, ref) {
var children = props.children,
classNameProp = props.className,
clone = props.clone,
ComponentProp = props.component,
other = _objectWithoutProperties(props, ["children", "className", "clone", "component"]);
var classes = useStyles(props);
var className = clsx(classes.root, classNameProp);
if (clone) {
return React.cloneElement(children, {
className: clsx(children.props.className, className)
});
}
var spread = other;
if (filterProps) {
spread = omit(spread, filterProps);
}
if (typeof children === 'function') {
return children(_extends({
className: className
}, spread));
}
var FinalComponent = ComponentProp || Component;
return React.createElement(FinalComponent, _extends({
ref: ref,
className: className
}, spread), children);
});
process.env.NODE_ENV !== "production" ? StyledComponent.propTypes = _extends({
/**
* A render function or node.
*/
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the component will recycle it's children DOM element.
* It's using `React.cloneElement` internally.
*/
clone: chainPropTypes(PropTypes.bool, function (props) {
if (props.clone && props.component) {
return new Error('You can not use the clone and component properties at the same time.');
}
return null;
}),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.elementType
}, propTypes) : void 0;
if (process.env.NODE_ENV !== 'production') {
StyledComponent.displayName = "Styled(".concat(classNamePrefix, ")");
}
hoistNonReactStatics(StyledComponent, Component);
return StyledComponent;
};
return componentCreator;
}
export default styled;
|
responsive-visualizations-with-react/presentation.js
|
okonet/slides
|
import React, { Component } from 'react';
import Deck from "components/Deck.react";
import Slide from "components/Slide.react";
import Code from "components/Code.react";
import DocumentTitle from "react-document-title";
import demo1 from 'babel!./examples/demo1';
import demo1Code from 'raw!./examples/demo1';
import demo2 from 'babel!./examples/demo2';
import demo2Code from 'raw!./examples/demo2';
import demo3 from 'babel!./examples/demo3';
import demo3Code from 'raw!./examples/demo3';
import demo3ExplicitCode from 'raw!./examples/demo3-explicit';
import demoSvg from 'babel!./examples/demo-svg';
import demoSvgCode from 'raw!./examples/demo-svg';
import demoHtml from 'babel!./examples/demo-html';
import demoHtmlCode from 'raw!./examples/demo-html';
import demoCss from 'babel!./examples/demo-css';
import demoCssCode from 'raw!./examples/demo-css';
import "css/theme.css";
const TOPIC = 'Responsive Visualizations with React';
const SPEAKER = (<span>by <a href="http://okonet.ru">Andrey Okonetchnikov</a></span>)
import 'prismjs/components/prism-json'
import 'prismjs/components/prism-jsx'
import 'style!css!prismjs/themes/prism-solarizedlight.css'
export default () =>
<DocumentTitle title={TOPIC}>
<Deck>
<header className="caption">
<h1>{TOPIC}</h1>
<p>{SPEAKER}</p>
</header>
<Slide className="cover-me">
<h2>{TOPIC}</h2>
<p>{SPEAKER}</p>
</Slide>
<Slide>
<div className="profile">
<img
className="profile__photo"
src="https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg"
alt="Andrey Okonetchnikov"
/>
<div className="profile__data">
<h2>Andrey Okonetchnikov</h2>
<h3>Front-end Engineer</h3>
<ul>
<li><a href="https://twitter.com/okonetchnikov">@okonetchnikov</a></li>
<li><a href="http://okonet.ru">okonet.ru</a></li>
<li><a href="github.com/okonet">github.com/okonet</a></li>
</ul>
</div>
</div>
</Slide>
<Slide className="picture">
<div className="place text-centered">
<h2>
<a href="http://status.postmarkapp.com" className="link">http://status.postmarkapp.com</a>
</h2>
</div>
<img src={require('./assets/status-responsive.gif')} alt="" className="cover" />
</Slide>
<Slide>
<h2>Simple chart</h2>
{demo1}
</Slide>
<Slide className="code_small">
<h2>Simple chart</h2>
<Code code={demo1Code} lang="jsx" />
</Slide>
<Slide className="code_small">
<h2>Resizeable chart?</h2>
<Code code={demo2Code} lang="jsx" />
</Slide>
<Slide>
<h2>Resizeable chart?</h2>
{demo2}
</Slide>
<Slide>
<h2 className="place emoji">🙄</h2>
</Slide>
<Slide>
<h2 className="shout shrink">Let’s fix it!</h2>
</Slide>
<Slide>
<div className="place">
<Code code="npm install react-container-dimensions" lang="bash"></Code>
</div>
</Slide>
<Slide className="code_small">
<h2>Before</h2>
<Code code={demo2Code} lang="jsx" />
</Slide>
<Slide className="code_small">
<h2>After</h2>
<Code code={demo3Code} lang="jsx" />
</Slide>
<Slide>
<h2>Resizeable chart!</h2>
{demo3}
</Slide>
<Slide>
<h2 className="place emoji">🙌</h2>
</Slide>
<Slide className="code_small">
<h2>Implicit props</h2>
<Code code={demo3Code} lang="jsx" />
</Slide>
<Slide className="code_small">
<h2>Explicit props</h2>
<Code code={demo3ExplicitCode} lang="jsx" />
</Slide>
<Slide>
<h2 className="shout shrink">Let’s get creative!</h2>
</Slide>
<Slide className="code_small">
<h2>Math based on container dimensions</h2>
<Code code={demoSvgCode} lang="jsx" />
</Slide>
<Slide>
<h2>Math based on container dimensions</h2>
{demoSvg}
</Slide>
<Slide className="code_small">
<h2>Works with any element</h2>
<Code code={demoHtmlCode} lang="jsx" />
</Slide>
<Slide>
<h2>Works with any element</h2>
{demoHtml}
</Slide>
<Slide className="code_small">
<h2>Reacts on any CSS change</h2>
<Code code={demoCssCode} lang="jsx" />
</Slide>
<Slide>
<h2>Reacts on any CSS change</h2>
{demoCss}
</Slide>
<Slide>
<p className="place emoji">😎</p>
</Slide>
<Slide>
<h2>How does it work?</h2>
<ol>
<li>Uses <a hred="https://github.com/wnr/element-resize-detector">element-resize-detector</a> under the hood</li>
<li>Doesn’t create a <code>div</code> element between components</li>
<li>Updates even on CSS changes</li>
<li>Just wrap a component that accepts <code>width</code> and <code>height</code></li>
<li>Or use a function that returns a component</li>
<li>Higher-Order Component? (send me your PR!)</li>
</ol>
</Slide>
<Slide>
<div className="place text-centered">
<h2>
<a href="https://github.com/okonet/react-container-dimensions" className="link">react-container-dimensions</a>
</h2>
<h3>🍴 or 🌟 it on GitHub</h3>
</div>
</Slide>
<Slide>
<h2 className="shout shrink">Breaking news!</h2>
</Slide>
<Slide className="picture">
<h2>Pictures</h2>
<img src={require('./assets/twitter-conv.png')} alt="" className="cover" />
</Slide>
<Slide>
<h2>Bad news for <code>this.findDOMNode()</code></h2>
<figure>
<blockquote>
<p>We think leaking internal details (state or DOM) should be explicit. Coupling should be intentional or it's easy to break.</p>
</blockquote>
<figcaption>Dan Abramov</figcaption>
</figure>
</Slide>
<Slide>
<h2>Bad news for <code>this.findDOMNode()</code></h2>
<figure>
<blockquote>
<p>There are almost no situations where you’d want to use findDOMNode() over callback refs. We want to deprecate it eventually (not right now) because it blocks certain improvements in React in the future.</p>
</blockquote>
<figcaption>Dan Abramov</figcaption>
</figure>
</Slide>
<Slide>
<div className="place text-centered">
<h2>
<a href="https://github.com/yannickcr/eslint-plugin-react/issues/678" className="link">https://github.com/yannickcr/eslint-plugin-react/issues/678</a>
</h2>
</div>
</Slide>
<Slide>
<h2 className="shout shrink">Expect some API changes</h2>
</Slide>
<Slide>
<h2 className="shout shrink">Thank you!</h2>
</Slide>
<Slide>
<div className="profile">
<img
className="profile__photo"
src="https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg"
alt="Andrey Okonetchnikov"
/>
<div className="profile__data">
<h2>Andrey Okonetchnikov</h2>
<h3>Front-end Engineer</h3>
<ul>
<li><a href="https://twitter.com/okonetchnikov">@okonetchnikov</a></li>
<li><a href="http://okonet.ru">okonet.ru</a></li>
<li><a href="github.com/okonet">github.com/okonet</a></li>
</ul>
</div>
</div>
</Slide>
</Deck>
</DocumentTitle>
|
src/svg-icons/action/all-out.js
|
xmityaz/material-ui
|
import React from 'react';
import pure from 'recompose/pure';
import SvgIcon from '../../SvgIcon';
let ActionAllOut = (props) => (
<SvgIcon {...props}>
<path d="M16.21 4.16l4 4v-4zm4 12l-4 4h4zm-12 4l-4-4v4zm-4-12l4-4h-4zm12.95-.95c-2.73-2.73-7.17-2.73-9.9 0s-2.73 7.17 0 9.9 7.17 2.73 9.9 0 2.73-7.16 0-9.9zm-1.1 8.8c-2.13 2.13-5.57 2.13-7.7 0s-2.13-5.57 0-7.7 5.57-2.13 7.7 0 2.13 5.57 0 7.7z"/>
</SvgIcon>
);
ActionAllOut = pure(ActionAllOut);
ActionAllOut.displayName = 'ActionAllOut';
ActionAllOut.muiName = 'SvgIcon';
export default ActionAllOut;
|
examples/full-example/isomorphic/variations/feature_B/components/_test_/toolbar_test.js
|
stephanwlee/mendel
|
/* Copyright 2015, Yahoo Inc.
Copyrights licensed under the MIT License.
See the accompanying LICENSE file for terms. */
import React from 'react'; // eslint-disable-line no-unused-vars
import { findDOMNode } from 'react-dom'; // eslint-disable-line no-unused-vars
import {
renderIntoDocument,
scryRenderedDOMComponentsWithTag
} from 'react-addons-test-utils';
import Toolbar from '../toolbar';
import {expect} from 'chai';
describe("toolbar feature_B", function() {
it("contains 3 buttons", function() {
const toolbar = renderIntoDocument(<Toolbar />);
const buttons = scryRenderedDOMComponentsWithTag(toolbar, 'button');
expect(buttons.length).to.equal(3);
expect(findDOMNode(buttons[0]).innerText).to.equal('B');
expect(findDOMNode(buttons[1]).innerText).to.equal('B');
expect(findDOMNode(buttons[2]).innerText).to.equal('B');
});
});
|
src/views/HomeView.js
|
mjosh954/mtg-toolbox
|
import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
// import Paper from 'material-ui/lib/paper';
import FlatButton from 'material-ui/lib/flat-button';
import CardTitle from 'material-ui/lib/card/card-title';
import GitHubForkRibbon from 'react-github-fork-ribbon';
import Dice from '../components/Dice';
export class HomeView extends React.Component {
render () {
return (
<div style={{width: '100%', padding: '50px'}}>
<GitHubForkRibbon href='https://github.com/mjosh954/mtg-toolbox' target='_blank' position='right' color='black'>Fork me on Github</GitHubForkRibbon>
<div style={{textAlign: 'center', margin: '20px'}}>
<img src={require('../assets/magic_elements.png')} />
<CardTitle title='MTG Toolbox' subtitle='A kit for all your MTG game needs.' />
<FlatButton containerElement={<Link to='/game' />} style={{width: '150px'}} linkButton label='Game Counter' />
<div style={{marginTop: '10px'}}>
<Dice buttonWidth='150' style={{marginTop: '5px'}} />
</div>
<div style={{marginTop: '10px'}}>
<FlatButton containerElement={<Link to='/draft/signup' />} style={{width: '150px'}} linkButton label='Draft Signup' />
</div>
</div>
</div>
);
}
}
export default connect()(HomeView);
|
src/components/Root/index.js
|
Apozhidaev/ergonode.com
|
import React, { Component } from 'react';
import moment from 'moment';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { search, showMore } from 'store/app/book/root/actions';
import { navigate } from 'store/services/history/actions';
import Layout from '../Layout';
import StatePanel from '../StatePanel';
import ProgressBar from '../ProgressBar';
class Root extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.clear = this.clear.bind(this);
this.create = this.create.bind(this);
}
handleChange(event) {
const { onSearch } = this.props;
onSearch(event.target.value);
}
clear() {
const { onSearch } = this.props;
onSearch('');
}
create() {
const { onNavigate } = this.props;
onNavigate({ path: '/new' });
}
render() {
const { root, storageFetching, onShowMore } = this.props;
const slots = root.displaySlots.map(slot => (<Link
key={slot.id.toString()}
to={`/slot/${slot.id}`}
className="list-group-item list-group-item-action flex-column align-items-start"
>
<div className="d-flex w-100 justify-content-between">
{slot.content
? <h5 className="mb-1">{slot.summary}</h5>
: <div>{slot.summary}</div>}
<small>{moment(slot.creation).format('L')}</small>
</div>
{slot.content && <pre className="mb-1">{slot.content.encrypted
? <em className="text-warning">information is encrypted</em>
: slot.content.value}</pre>}
</Link>));
return (
<Layout>
<div className="row">
<div className="col">
<div className="btn-toolbar justify-content-between" role="toolbar">
<div className="btn-group my-2" role="group" />
<div className="btn-group my-2" role="group">
<button type="button" className="btn btn-outline-success" onClick={this.create}>
new
</button>
</div>
</div>
</div>
</div>
<div className="row mb-3">
<div className="col-md-2">
<StatePanel />
</div>
<div className="col-md-10">
<div className="row">
<div className="col">
<div className="input-group my-2">
<input
type="text"
className="form-control"
placeholder="search..."
value={root.searchQuery}
onChange={this.handleChange}
/>
{root.searchQuery && <span className="input-group-btn">
<button
type="button"
className="btn btn-secondary"
onClick={this.clear}
>
×
</button>
</span>}
</div>
</div>
</div>
<div className="row">
<div className="col">
<ProgressBar progress={storageFetching && !slots.length && !root.searchQuery} />
<div className="list-group">
{!slots.length && root.searchQuery && <p className="p-2">slot not found</p>}
{slots}
</div>
{root.canMore &&
<div className="d-flex justify-content-center">
<button
type="button"
className="btn btn-outline-info my-2"
onClick={onShowMore}
>
more...
</button>
</div>
}
</div>
</div>
</div>
</div>
</Layout>
);
}
}
const mapStateToProps = state => ({
root: state.app.book.root,
storageFetching: state.services.sso.storageFetching,
});
const mapDispatchToProps = ({
onSearch: search,
onNavigate: navigate,
onShowMore: showMore,
});
export default connect(mapStateToProps, mapDispatchToProps)(Root);
|
src/Table.js
|
sheep902/react-bootstrap
|
import React from 'react';
import classNames from 'classnames';
const Table = React.createClass({
propTypes: {
striped: React.PropTypes.bool,
bordered: React.PropTypes.bool,
condensed: React.PropTypes.bool,
hover: React.PropTypes.bool,
responsive: React.PropTypes.bool
},
getDefaultProps() {
return {
bordered: false,
condensed: false,
hover: false,
responsive: false,
striped: false
};
},
render() {
let classes = {
'table': true,
'table-striped': this.props.striped,
'table-bordered': this.props.bordered,
'table-condensed': this.props.condensed,
'table-hover': this.props.hover
};
let table = (
<table {...this.props} className={classNames(this.props.className, classes)}>
{this.props.children}
</table>
);
return this.props.responsive ? (
<div className="table-responsive">
{table}
</div>
) : table;
}
});
export default Table;
|
front/src/components/App/Video/index.js
|
MichaelKostin/mars-rover
|
import React, { Component } from 'react';
import WebSocketSignalingChannel from '../../../rwsClient/WebSocketSignalingChannel';
import './style.css';
export default class Video extends Component {
constructor(props) {
super(props);
this.video = null;
this.connect = null;
this.disconnect = null;
this.client = null;
}
componentDidMount() {
this.client = new WebSocketSignalingChannel(this.connect, this.disconnect, this.video);
}
render() {
return (
<section>
<video
ref={(videoRef) => this.video = videoRef}
autoPlay
playsInline
controls
muted
width="100%"
height="384"
/>
<div className="web-rtc-controls">
<button ref={(connectRef) => this.connect = connectRef}>Connect</button>
<button ref={(disconnectRef) => this.disconnect = disconnectRef}>Disconnect</button>
</div>
</section>
)
}
}
|
docs/src/examples/elements/Loader/Variations/LoaderExampleInlineCentered.js
|
Semantic-Org/Semantic-UI-React
|
import React from 'react'
import { Loader } from 'semantic-ui-react'
const LoaderExampleInlineCentered = () => <Loader active inline='centered' />
export default LoaderExampleInlineCentered
|
ui/src/components/SmallSpinner/index.js
|
LearningLocker/learninglocker
|
import React from 'react';
import styled from 'styled-components';
import { rotation } from 'ui/utils/styled/animations';
const SmallSpinner = styled.div`
height: 1.5em;
width: 1.5em;
margin: auto;
animation: ${rotation} .6s infinite linear;
border-left: 4px solid rgba(245, 170, 53, 0.15);
border-right: 4px solid rgba(245, 170, 53, 0.15);
border-bottom: 4px solid rgba(245, 170, 53, 0.15);
border-top: 4px solid rgba(245, 170, 53, 0.8);
border-radius: 100%;
`;
const smallSpinner = () => (<SmallSpinner />);
export default smallSpinner;
|
client/src/MagicModeMarker.js
|
jghibiki/Doc
|
import React from 'react';
import AllInclusiveIcon from '@material-ui/icons/AllInclusive';
import Chip from '@material-ui/core/Chip';
import Avatar from '@material-ui/core/Avatar';
import MagicModeMarkerDialog from './MagicModeMarkerDialog.js'
const MagicModeMarker = (props) => {
const [dialogOpen, setDialogOpen] = React.useState(false);
const [video, setVideo] = React.useState(props.video || null);
const handleOpen = () => {
setDialogOpen(true)
}
const handleClose = () => {
setDialogOpen(false)
}
if(video !== null){
return (
<div>
<Chip avatar={<Avatar><AllInclusiveIcon/></Avatar>} onClick={handleOpen} label="Magic Mode" />
<MagicModeMarkerDialog open={dialogOpen} onClose={handleClose} video={video}/>
</div>
)
}
else{
return (
<div>
<Chip avatar={<Avatar><AllInclusiveIcon/></Avatar>} label="Magic Mode" />
</div>
)
}
}
export default MagicModeMarker
|
app/containers/LinkFormContainer/index.js
|
GeertHuls/react-async-saga-example
|
/*
*
* LinkFormContainer
*
*/
import React from 'react';
import { connect } from 'react-redux';
import selectLinkFormContainer from './selectors';
import LinkForm from '../../components/LinkForm';
import { addLink, addLinkCancelled } from './actions';
export class LinkFormContainer extends React.Component { // eslint-disable-line react/prefer-stateless-function
render() {
return (
<LinkForm {...this.props} />
);
}
}
const mapStateToProps = selectLinkFormContainer();
function mapDispatchToProps(dispatch) {
return {
addLink: (link) => dispatch(addLink(link)),
addLinkCancelled: () => dispatch(addLinkCancelled()),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(LinkFormContainer);
|
app/scripts/routes.js
|
shawnrmoss/rsk
|
import React from 'react';
import { Router, Route } from 'react-router';
import createHistory from 'history/lib/createHashHistory'
import App from './pages/app.jsx';
import Home from './pages/home.jsx';
import Info from './pages/info.jsx';
import NotFound from './pages/notFound.jsx';
import Login from './pages/Login/Login.jsx';
import {requireAuthentication} from './components/AuthenticatedComponent/AuthenticatedComponent.jsx';
const routes = (
<Router history={createHistory()}>
<Route component={ Login } name="Login" path="Login"/>
<Route path='/' component={ requireAuthentication(App) }>
<Route path='info' component={ Info } />
<Route path='home' component={ Home } />
<Route path='*' component={NotFound}/>
</Route>
</Router>
);
export default routes;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.