Skip to content

Commit

Permalink
build: update eslint package and config
Browse files Browse the repository at this point in the history
using a modified mobile repo .eslintrc

ran format / lint on all files

for whatever reason the formatter swaps imports/require statements, which the linter (both are eslint) complains about being incorrectly ordered

using the simple import sort plugin works correctly for imports and doesn't re-order require statements, so manually ordering as opposed to manually saving without format on save

i suspect this may also have to do with my broken vs code update and eslint insider extension
  • Loading branch information
bhajneet authored and Harjot1Singh committed Oct 20, 2020
1 parent 295e3f4 commit 8ae2010
Show file tree
Hide file tree
Showing 17 changed files with 784 additions and 1,246 deletions.
86 changes: 51 additions & 35 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,61 +1,77 @@
{
"extends": "airbnb",
"extends": "airbnb-base",
"root": true,
"env": {
"es6": true,
"mocha": true
},
"plugins": ["simple-import-sort"],
"rules": {
"array-bracket-spacing": [
"error",
"always"
],
"arrow-parens": [
// Spacing in brackets is consistent and readable
"array-bracket-spacing": ["error", "always"],
// Spacing in brackets is consistent and readable
"computed-property-spacing": ["error", "always"],
// Spacing in brackets is consistent and readable
"space-in-parens": [
"error",
"as-needed",
"always",
{
"requireForBlockBody": false
"exceptions": ["empty"]
}
],
"computed-property-spacing": [
// Doesn't really help to check if the module is on the filesystem, and can harm when using Docker etc: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
"import/no-unresolved": "off",
// Do not require .js/ts extensions, except for .json
"import/extensions": [
"error",
"always"
],
"func-names": [
"warn",
"never"
"never",
{
"json": "always"
}
],
"import/extensions": "off",
"import/no-unresolved": "off",
// Preferable, but the author should know best for the situation
"import/prefer-default-export": "off",
// Windows users may checkout as CRLF, but check in as LF, which this rule breaks
"linebreak-style": "off",
"no-await-in-loop": "off",
"no-loop-func": "off",
"no-restricted-syntax": "off",
"no-shadow": "off",
// There's no need to have more than 1 empty line, ever
"no-multiple-empty-lines": [
"error",
{
"max": 1
}
],
// No unused variables except when prepended with _, to indicate that they're not to be used, but require definition to be valid code
"no-unused-vars": [
"warn",
"error",
{
"argsIgnorePattern": "(res|next)"
"ignoreRestSiblings": true,
"argsIgnorePattern": "^_"
}
],
// https://eslint.org/docs/rules/no-shadow seems sensible to not have shadow variables, but can get annoying real quick, especially in the case of reducers
"no-shadow": "off",
// Be consistent about where the object braces go
"object-curly-newline": [
"error",
{
"consistent": true
}
],
"react/jsx-filename-extension": "off",
"require-jsdoc": "warn",
"semi": [
"error",
"never"
],
"semi-style": [
// Object properties either on the same line, or all on separate, consistently
"object-property-newline": [
"error",
"first"
{
"allowAllPropertiesOnSameLine": true
}
],
"space-in-parens": [
"error",
"always"
]
// Semi colons are visual garbage
"semi": ["error", "never"],
// For the few semi-colons required (e.g. inline array operations), place them at the beginning of the statement
"semi-style": ["error", "first"],
// This plugin sorts alphabetically by default
"simple-import-sort/sort": "error",
// Add new line between imports
"import/order": "off",
"sort-imports": "off"
}
}
}
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ Want to play around? [![Try gurmukhi-utils on RunKit](https://badge.runkitcdn.co
## API

### firstLetters(line) ⇒ <code>String</code>
Generates the first letters for a unicode Gurmukhi,
Hindi transliteration, or English transliteration string.
Includes any end-word vishraams, and line-end characters.
Generates the first letters for a unicode Gurmukhi,Hindi transliteration, or English transliteration string.Includes any end-word vishraams, and line-end characters.

**Returns**: <code>String</code> - The first letters of each word in the provided Gurmukhi line.

Expand Down Expand Up @@ -126,10 +124,7 @@ stripAccents('ਜ਼ਫ਼ੈਸ਼ਸਓ') // => ਜਫੈਸਸੳ
stripAccents('Z^Svb') // => gKsvb
```
### stripEndings(text) ⇒ <code>String</code>
Strips line endings from any Gurmukhi or translation string.
Accepts both Unicode and ASCII input.
Useful for generating accurate first letters or modifying non-Gurbani for better display.
*Not* designed for headings or Sirlekhs.
Strips line endings from any Gurmukhi or translation string.Accepts both Unicode and ASCII input.Useful for generating accurate first letters or modifying non-Gurbani for better display.*Not* designed for headings or Sirlekhs.

**Returns**: <code>String</code> - A ending-less version of the text.

Expand Down Expand Up @@ -196,8 +191,7 @@ toAscii('ਹਮਾ ਸਾਇਲਿ ਲੁਤਫ਼ਿ ਹਕ ਪਰਵਰਸ਼ ॥')
toAscii('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => su bYiT iekMqR ]578]
```
### toEnglish(line) ⇒ <code>String</code>
Transliterates a line from Unicode Gurmukhi to english.
Currently supports the `,`, `;`, `.` vishraam characters.
Transliterates a line from Unicode Gurmukhi to english.Currently supports the `,`, `;`, `.` vishraam characters.

**Returns**: <code>String</code> - The English transliteration of the provided Gurmukhi line.

Expand Down
12 changes: 3 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ Want to play around? [![Try gurmukhi-utils on RunKit](https://badge.runkitcdn.co
## API

### firstLetters(line) ⇒ <code>String</code>
Generates the first letters for a unicode Gurmukhi,
Hindi transliteration, or English transliteration string.
Includes any end-word vishraams, and line-end characters.
Generates the first letters for a unicode Gurmukhi,Hindi transliteration, or English transliteration string.Includes any end-word vishraams, and line-end characters.

**Returns**: <code>String</code> - The first letters of each word in the provided Gurmukhi line.

Expand Down Expand Up @@ -126,10 +124,7 @@ stripAccents('ਜ਼ਫ਼ੈਸ਼ਸਓ') // => ਜਫੈਸਸੳ
stripAccents('Z^Svb') // => gKsvb
```
### stripEndings(text) ⇒ <code>String</code>
Strips line endings from any Gurmukhi or translation string.
Accepts both Unicode and ASCII input.
Useful for generating accurate first letters or modifying non-Gurbani for better display.
*Not* designed for headings or Sirlekhs.
Strips line endings from any Gurmukhi or translation string.Accepts both Unicode and ASCII input.Useful for generating accurate first letters or modifying non-Gurbani for better display.*Not* designed for headings or Sirlekhs.

**Returns**: <code>String</code> - A ending-less version of the text.

Expand Down Expand Up @@ -196,8 +191,7 @@ toAscii('ਹਮਾ ਸਾਇਲਿ ਲੁਤਫ਼ਿ ਹਕ ਪਰਵਰਸ਼ ॥')
toAscii('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => su bYiT iekMqR ]578]
```
### toEnglish(line) ⇒ <code>String</code>
Transliterates a line from Unicode Gurmukhi to english.
Currently supports the `,`, `;`, `.` vishraam characters.
Transliterates a line from Unicode Gurmukhi to english.Currently supports the `,`, `;`, `.` vishraam characters.

**Returns**: <code>String</code> - The English transliteration of the provided Gurmukhi line.

Expand Down
6 changes: 3 additions & 3 deletions lib/firstLetters.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const vowelFirstLetters = {
* @example <caption>English first letters</caption>
* firstLetters('sabad marai. so mar rahai; fir. marai na, doojee vaar |') // => sm.smr;f.mn,dv|
*/
const firstLetters = line => line
const firstLetters = ( line ) => line
// Split into words
.split( ' ' )
// Remove any wrods that are excess spaces
.filter( word => word.trim().length )
.filter( ( word ) => word.trim().length )
// Grab correct letter of each word
.map( word => {
.map( ( word ) => {
const [ letter ] = word
const lastLetter = word[ word.length - 1 ]

Expand Down
4 changes: 2 additions & 2 deletions lib/isGurmukhi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const vishraams = Object.values( require( './vishraams.json' ) )

// Checks if Unicode Text is in Gurmukhi Block (U+0A00 - U+0A7F)
const checkCharCode = text => ( text.charCodeAt( 0 ) >= 2560 && text.charCodeAt( 0 ) <= 2687 )
const checkCharCode = ( text ) => ( text.charCodeAt( 0 ) >= 2560 && text.charCodeAt( 0 ) <= 2687 )

// Characters to filter from text if doing an exhaustive check
const filteredChars = [
Expand All @@ -24,7 +24,7 @@ const filteredChars = [
const isGurmukhi = ( text, exhaustive ) => (
exhaustive
? text.split( '' )
.filter( i => !filteredChars.includes( i ) )
.filter( ( i ) => !filteredChars.includes( i ) )
.every( checkCharCode )
: checkCharCode( text )
)
Expand Down
4 changes: 2 additions & 2 deletions lib/regex-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const escapeStringRegexp = require( 'escape-string-regexp' )

const getRegexClass = characters => `[${characters.map( escapeStringRegexp ).join( '' )}]`
const getRegexClass = ( characters ) => `[${characters.map( escapeStringRegexp ).join( '' )}]`

const getRegexGroup = characters => `(${characters.map( escapeStringRegexp ).join( '|' )})`
const getRegexGroup = ( characters ) => `(${characters.map( escapeStringRegexp ).join( '|' )})`

module.exports = { getRegexClass, getRegexGroup }
17 changes: 11 additions & 6 deletions lib/stripAccents.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const toAscii = require( './toAscii' )

// The mappings from the letter-variations to simple Gurmukhi letters
const unicodeBaseLetterMap = require( './accents.json' )

// Generate both unicode and ASCII mappings
const baseLetterMap = {
...unicodeBaseLetterMap,
...Object.entries( unicodeBaseLetterMap ).reduce( ( letters, [ from, to ] ) => ( {
...letters,
[ toAscii( from ) ]: toAscii( to ),
} ), {} ),
...Object.entries( unicodeBaseLetterMap ).reduce(
( letters, [ from, to ] ) => ( {
...letters,
[ toAscii( from ) ]: toAscii( to ),
} ),
{},
),
}

/**
Expand All @@ -21,6 +23,9 @@ const baseLetterMap = {
* stripAccents('ਜ਼ਫ਼ੈਸ਼ਸਓ') // => ਜਫੈਸਸੳ
* stripAccents('Z^Svb') // => gKsvb
*/
const stripAccents = text => text.split( '' ).map( char => baseLetterMap[ char ] || char ).join( '' )
const stripAccents = ( text ) => text
.split( '' )
.map( ( char ) => baseLetterMap[ char ] || char )
.join( '' )

module.exports = stripAccents
7 changes: 3 additions & 4 deletions lib/stripEndings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const optionalEndingClass = getRegexClass( [ '(' ] )
const brokenEndingClass = getRegexGroup( [ '()' ] )

// All numbers in ASCII, Unicode
const numbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ].map( i => i.toString() )
const numbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ].map( ( i ) => i.toString() )
const numberClass = getRegexClass( [
...numbers,
...numbers.map( toUnicode ),
Expand All @@ -29,8 +29,7 @@ const matchers = [
// Clean up any lingering ending characters
` ?${brokenEndingClass}`,
` ?${endingClass}`,
].map( exp => new RegExp( exp, 'g' ) )

].map( ( exp ) => new RegExp( exp, 'g' ) )

/**
* Strips line endings from any Gurmukhi or translation string.
Expand All @@ -51,6 +50,6 @@ const matchers = [
* @example <caption>Spanish Translations</caption>
* stripEndings('ofrece su ser en sacrificio a Ti. (4-2-9)') // => ofrece su ser en sacrificio a Ti.
*/
const stripEndings = text => matchers.reduce( ( text, exp ) => text.replace( exp, '' ), text ).trim()
const stripEndings = ( text ) => matchers.reduce( ( text, exp ) => text.replace( exp, '' ), text ).trim()

module.exports = stripEndings
2 changes: 1 addition & 1 deletion lib/stripVishraams.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const vishraams = require( './vishraams.json' )
const { getRegexClass } = require( './regex-utils' )

const vishraamRegExp = vishraams => new RegExp( getRegexClass( vishraams ), 'g' )
const vishraamRegExp = ( vishraams ) => new RegExp( getRegexClass( vishraams ), 'g' )

/**
* Removes the specified vishraams from a string.
Expand Down
3 changes: 2 additions & 1 deletion lib/toAscii.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const escapeStringRegexp = require( 'escape-string-regexp' )

const unicodeMappings = require( './unicodeMappings' )

// Make each mapping an escaped global regex, and flip around the mappings
Expand Down Expand Up @@ -54,7 +55,7 @@ const finalReplacements = [
* toAscii('ਹਮਾ ਸਾਇਲਿ ਲੁਤਫ਼ਿ ਹਕ ਪਰਵਰਸ਼ ॥') // => hmw swieil luqi& hk prvrS ]
* toAscii('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => su bYiT iekMqR ]578]
*/
const toAscii = text => finalReplacements
const toAscii = ( text ) => finalReplacements
.reduce( ( text, [ exp, sub ] ) => text.replace( exp, sub ), text )

module.exports = toAscii
15 changes: 6 additions & 9 deletions lib/toEnglish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const toAscii = require( './toAscii' )

// Vishraam characters
const vishraams = Object.values( require( './vishraams' ) )

// Spacer characters
Expand Down Expand Up @@ -115,18 +113,18 @@ const replacements = [
// Rules required to add in an extra a letter - all must be true
const extraARules = [
// Current letter is alphanumeric
letter => !!letter.match( /[a-zA-Z]/g ),
( letter ) => !!letter.match( /[a-zA-Z]/g ),
// Case-insensitive current letter is not a vowel
letter => `aeiou${spaceChars}ooaiee`.indexOf( letter.toLowerCase() ) === -1,
( letter ) => `aeiou${spaceChars}ooaiee`.indexOf( letter.toLowerCase() ) === -1,
// Current letter is not a n-ending type sound
letter => ![
( letter ) => ![
transliterationMap.N,
transliterationMap.M,
transliterationMap.W,
transliterationMap[ 'ƒ' ],
].includes( letter ),
// Current letter is not Ik or Oankaar
letter => ![
( letter ) => ![
transliterationMap[ '<' ],
transliterationMap[ '>' ],
transliterationMap[ '¡' ],
Expand Down Expand Up @@ -169,7 +167,6 @@ const finalReplacements = Object.entries( {
// Convert to global regular expressions
.map( ( [ exp, sub ] ) => [ new RegExp( exp, 'ug' ), sub ] )


/**
* Transliterates a line from Unicode Gurmukhi to english.
* Currently supports the `,`, `;`, `.` vishraam characters.
Expand All @@ -180,7 +177,7 @@ const finalReplacements = Object.entries( {
* @example
* toEnglish('ਭਾਂਡਾ ਭਾਉ ਅੰਮ੍ਰਿਤੁ ਤਿਤੁ ਢਾਲਿ ॥') // => bhaa(n)ddaa bhaou anmrit tit dtaal ||
*/
const toEnglish = line => {
const toEnglish = ( line ) => {
// Work out transliterated line
const transliterated = replacements
// Carry out initial replacements
Expand All @@ -196,7 +193,7 @@ const toEnglish = line => {
let mappedLetter = transliterationMap[ letter ] || letter

// Add in extra `a` if every rule is met
if ( extraARules.every( fn => fn( mappedLetter, nextLetter, nextNextLetter ) ) ) { mappedLetter += 'a' }
if ( extraARules.every( ( fn ) => fn( mappedLetter, nextLetter, nextNextLetter ) ) ) { mappedLetter += 'a' }

return mappedLetter
} )
Expand Down
2 changes: 1 addition & 1 deletion lib/toHindi.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const finalReplacements = [
* toHindi('ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥') // => कुल जन मधे मिल्यो सारग पान रे ॥
* toHindi('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => सु बैठ इकंत्र ॥५७८॥
*/
const toHindi = text => finalReplacements
const toHindi = ( text ) => finalReplacements
.reduce( ( text, [ exp, sub ] ) => text.replace( exp, sub ), text )

module.exports = toHindi
2 changes: 1 addition & 1 deletion lib/toShahmukhi.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const finalReplacements = [ ...replacements, ...mappings ]
* toShahmukhi('ਹਮਾ ਸਾਇਲਿ ਲੁਤਫ਼ਿ ਹਕ ਪਰਵਰਸ਼ ॥') // => هما ساِال لُتف هک پرورش ۔۔
* toShahmukhi('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => سُ بَےٹھ ِاکںتر ۔۔۵۷۸۔۔
*/
const toShahmukhi = text => finalReplacements
const toShahmukhi = ( text ) => finalReplacements
.reduce( ( text, [ exp, sub ] ) => text.replace( exp, sub ), text )

module.exports = toShahmukhi
3 changes: 2 additions & 1 deletion lib/toUnicode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const escapeStringRegexp = require( 'escape-string-regexp' )

const unicodeMappings = require( './unicodeMappings' )

// Make each mapping an escaped global regex
Expand Down Expand Up @@ -27,7 +28,7 @@ const finalReplacements = [ ...replacements, ...mappings ]
* toUnicode('kul jn mDy imil´o swrg pwn ry ]') // => ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥
* toUnicode('su bYiT iekMqR ]578]') // => ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥
*/
const toUnicode = text => finalReplacements
const toUnicode = ( text ) => finalReplacements
.reduce( ( text, [ exp, sub ] ) => text.replace( exp, sub ), text )

module.exports = toUnicode
Loading

0 comments on commit 8ae2010

Please sign in to comment.