Start using eslint

This commit is contained in:
Greg Shuflin 2021-09-12 00:55:17 -07:00
parent 4de6e718ff
commit e8c53cda2f
5 changed files with 5207 additions and 4550 deletions

23
.eslintrc.js Normal file
View File

@ -0,0 +1,23 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'xo',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'react',
],
rules: {
"arrow-parens": ["error", "always"]
},
};

View File

@ -13,6 +13,9 @@
"devDependencies": { "devDependencies": {
"@parcel/transformer-image": "2.0.0-rc.0", "@parcel/transformer-image": "2.0.0-rc.0",
"@parcel/transformer-sass": "2.0.0-rc.0", "@parcel/transformer-sass": "2.0.0-rc.0",
"eslint": "^7.32.0",
"eslint-config-xo": "^0.38.0",
"eslint-plugin-react": "^7.25.1",
"parcel": "^2.0.0-rc.0" "parcel": "^2.0.0-rc.0"
}, },
"dependencies": { "dependencies": {

View File

@ -1,49 +1,50 @@
import React, { Component } from "react"; import React, {Component} from 'react';
import './App.scss'; import './App.scss';
import {declineSaimiar} from './saimiar_morphology.js'; import {declineSaimiar} from './saimiar_morphology.js';
const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com"; const backendUrl = 'https://kucinakobackend.ichigo.everydayimshuflin.com';
function makeRequest(queryString, jsonHandler) { function makeRequest(queryString, jsonHandler) {
const effectiveUrl = `${backendUrl}/${queryString}` const effectiveUrl = `${backendUrl}/${queryString}`;
fetch(`${effectiveUrl}`) fetch(`${effectiveUrl}`)
.then((resp) => { .then((resp) => resp.json())
return resp.json()
})
.then((json) => { .then((json) => {
jsonHandler(json); jsonHandler(json);
}); });
} }
function renderConlangName(name) { function renderConlangName(name) {
if (name == "saimiar") { if (name === 'saimiar') {
return "Saimiar"; return 'Saimiar';
}
if (name == "elesu") {
return "Elésu";
} }
if (name === "juteyuji") { if (name === 'elesu') {
return "Juteyuji"; return 'Elésu';
} }
if (name === "tukvaysi") {
return "Tukvaysi"; if (name === 'juteyuji') {
return 'Juteyuji';
}
if (name === 'tukvaysi') {
return 'Tukvaysi';
} }
} }
function Entry(props) { function Entry(props) {
const conlang = props.conlang; const {conlang} = props;
if (conlang === "saimiar") { if (conlang === 'saimiar') {
return <SaiEntry entry={ props.entry } />; return <SaiEntry entry={ props.entry } />;
} }
return <div>Unknown entry type for { conlang }</div>; return <div>Unknown entry type for { conlang }</div>;
} }
function SaiEntry(props) { function SaiEntry(props) {
const entry = props.entry; const {entry} = props;
const synCategory = entry.syn_category; const synCategory = entry.syn_category;
const isNominal = synCategory == 'nominal'; const isNominal = synCategory === 'nominal';
console.log(isNominal); console.log(isNominal);
return ( return (
<div className="searchResult" key={ entry.id }> <div className="searchResult" key={ entry.id }>
@ -64,6 +65,7 @@ function formatMorphology(entry) {
if (!decl) { if (!decl) {
return ''; return '';
} }
return (<span style={ {fontSize: 'medium', color: '#6a3131'} } > return (<span style={ {fontSize: 'medium', color: '#6a3131'} } >
Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>, Abs: <i>{decl.abs}</i>, Erg: <i>{decl.erg}</i>,
Adp: <i>{decl.adp}</i>, Adp: <i>{decl.adp}</i>,
@ -82,16 +84,16 @@ class Results extends Component {
} }
content() { content() {
const conlang = this.props.conlang; const {conlang} = this.props;
const num = this.props.searchResults.length; const num = this.props.searchResults.length;
const renderedName = renderConlangName(conlang); const renderedName = renderConlangName(conlang);
const searchType = (this.props.direction === "toConlang") ? `English -> ${renderedName}` : `${renderedName} -> English`; const searchType = (this.props.direction === 'toConlang') ? `English -> ${renderedName}` : `${renderedName} -> English`;
const header = ( const header = (
<div className="searchResultHeader" key="header"> <div className="searchResultHeader" key="header">
Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s) Searched for <b>{ this.props.searchTerm }</b>, { searchType }, found { num } result(s)
</div>); </div>);
const entries = this.props.searchResults.map( const entries = this.props.searchResults.map(
(entry, idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } /> (entry, _idx) => <Entry entry={ entry } key= { entry.id } conlang={ conlang } />,
); );
return [header].concat(entries); return [header].concat(entries);
} }
@ -99,8 +101,8 @@ class Results extends Component {
render() { render() {
const results = this.props.searchResults; const results = this.props.searchResults;
return ( return (
<div className='results'> <div className="results">
{ results ? this.content() : "No search" } { results ? this.content() : 'No search' }
</div> </div>
); );
} }
@ -117,32 +119,32 @@ class App extends Component {
this.state = { this.state = {
searchResults: null, searchResults: null,
conlang: "saimiar", conlang: 'saimiar',
direction: null, direction: null,
searchTerm: null searchTerm: null,
}; };
} }
searchSaimiar(evt) { searchSaimiar(_evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?sai=like.*${searchTerm}*` const request = `saimiar?sai=like.*${searchTerm}*`;
if (searchTerm === "") { if (searchTerm === '') {
this.setState({searchResults: null, searchTerm: null, direction: null}); this.setState({searchResults: null, searchTerm: null, direction: null});
} else { } else {
makeRequest(request, (json) => { makeRequest(request, (json) => {
this.setState({ searchResults: json, searchTerm, direction: "toEnglish" }); this.setState({searchResults: json, searchTerm, direction: 'toEnglish'});
}); });
} }
} }
searchEng(evt) { searchEng(_evt) {
const searchTerm = this.input.current.value; const searchTerm = this.input.current.value;
const request = `saimiar?eng=like.*${searchTerm}*` const request = `saimiar?eng=like.*${searchTerm}*`;
if (searchTerm === "") { if (searchTerm === '') {
this.setState({ searchResults: null, searchTerm: null, }); this.setState({searchResults: null, searchTerm: null});
} else { } else {
makeRequest(request, (json) => { makeRequest(request, (json) => {
this.setState({ searchResults: json, searchTerm, direction: "toConlang" }); this.setState({searchResults: json, searchTerm, direction: 'toConlang'});
}); });
} }
} }
@ -153,14 +155,13 @@ class App extends Component {
} }
render() { render() {
return ( return (
<main> <main>
<div className='container'> <div className="container">
<div className='search'> <div className="search">
<h1>Kucinako</h1> <h1>Kucinako</h1>
<div className='textInput'> <div className="textInput">
<input className='textInput' type="text" ref={ this.input } /> <input className="textInput" type="text" ref={ this.input } />
</div> </div>
<br/> <br/>
<select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar"> <select ref={ this.langSelection } onChange={ this.handleLangChange } defaultValue="saimiar">
@ -184,6 +185,4 @@ class App extends Component {
} }
} }
export default App; export default App;

View File

@ -1,72 +1,75 @@
const rootEndingPair = (str) => { const rootEndingPair = (str) => ({root: str.slice(0, -1), ending: str.slice(-1)});
return { root: str.slice(0, -1), ending: str.slice(-1) };
};
function declineSaimiar(entry) { function declineSaimiar(entry) {
const split = entry.sai.split(" "); const split = entry.sai.split(' ');
const sai = split.at(-1); const sai = split.at(-1);
const morph = entry.morph_type; const morph = entry.morph_type;
let declined; if (morph === '-V') {
if (morph == '-V') {
return vowelDeclension(sai); return vowelDeclension(sai);
} else if (morph == '-a/i') {
return aiDeclension(sai)
} else if (morph == "e-") {
return initalDeclension(sai);
} else if (morph == "-C") {
return consonantDeclension(sai);
} else {
console.warn(`Can't decline entry '${entry.sai}'`);
console.log(entry)
return null;
} }
if (morph === '-a/i') {
return aiDeclension(sai);
}
if (morph === 'e-') {
return initalDeclension(sai);
}
if (morph === '-C') {
return consonantDeclension(sai);
}
console.warn(`Can't decline entry '${entry.sai}'`);
console.log(entry);
return null;
} }
function vowelDeclension(sai) { function vowelDeclension(sai) {
const {root, ending} = rootEndingPair(sai); const {root, ending} = rootEndingPair(sai);
const adpEnding = ending == "u" ? "ys" : `${ending}s`; const adpEnding = ending === 'u' ? 'ys' : `${ending}s`;
return { return {
"abs": `${root}${ending}`, abs: `${root}${ending}`,
"erg": `${root}${ending}na`, erg: `${root}${ending}na`,
"adp": `${root}${adpEnding}`, adp: `${root}${adpEnding}`,
"all": `so${root}${adpEnding}`, all: `so${root}${adpEnding}`,
"loc": `${root}${ending}xa`, loc: `${root}${ending}xa`,
"ell": `tlê${root}${adpEnding}`, ell: `tlê${root}${adpEnding}`,
"inst": `${root}${ending}ŕa`, inst: `${root}${ending}ŕa`,
"rel": `${root}${ending}źi` rel: `${root}${ending}źi`,
}; };
} }
function aiDeclension(sai) { function aiDeclension(sai) {
const {root, ending} = rootEndingPair(sai); const {root, ending} = rootEndingPair(sai);
return { return {
"abs": `${root}${ending}`, abs: `${root}${ending}`,
"erg": `${root}iad`, erg: `${root}iad`,
"adp": `${root}i`, adp: `${root}i`,
"all": `so${root}i`, all: `so${root}i`,
"loc": `${root}iath`, loc: `${root}iath`,
"ell": `tlê${root}i`, ell: `tlê${root}i`,
"inst": `${root}iar`, inst: `${root}iar`,
"rel": `${root}iai` rel: `${root}iai`,
}; };
} }
function consonantDeclension(sai) { function consonantDeclension(sai) {
const split = rootEndingPair(sai); const split = rootEndingPair(sai);
const root = split.ending == 'ø' ? split.root : sai; const root = split.ending === 'ø' ? split.root : sai;
const absFinal = split.ending == 'ø' ? 'ø' : ''; const absFinal = split.ending === 'ø' ? 'ø' : '';
return { return {
"abs": `${root}${absFinal}`, abs: `${root}${absFinal}`,
"erg": `${root}ad`, erg: `${root}ad`,
"adp": `${root}e`, adp: `${root}e`,
"all": `so${root}i`, all: `so${root}i`,
"loc": `${root}ak`, loc: `${root}ak`,
"ell": `tlê${root}i`, ell: `tlê${root}i`,
"inst": `${root}ar`, inst: `${root}ar`,
"rel": `${root}ai` rel: `${root}ai`,
}; };
} }
@ -78,18 +81,18 @@ function initalDeclension(sai) {
const finalRootSound = root.slice(-1); const finalRootSound = root.slice(-1);
const finalVowel = vowels.includes(finalRootSound); const finalVowel = vowels.includes(finalRootSound);
const instEnding = finalVowel ? "ŕø" : "ar"; const instEnding = finalVowel ? 'ŕø' : 'ar';
const relEnding = finalVowel ? "źi" : "ai"; const relEnding = finalVowel ? 'źi' : 'ai';
return { return {
"abs": `${initial}${root}`, abs: `${initial}${root}`,
"erg": `da${root}`, erg: `da${root}`,
"adp": `i${root}`, adp: `i${root}`,
"all": `so${root}`, all: `so${root}`,
"loc": `xa${root}`, loc: `xa${root}`,
"ell": `tlê${root}`, ell: `tlê${root}`,
"inst": `i${root}${instEnding}`, inst: `i${root}${instEnding}`,
"rel": `${initial}${root}${relEnding}`, rel: `${initial}${root}${relEnding}`,
}; };
} }

9291
yarn.lock

File diff suppressed because it is too large Load Diff