Skip to content

Commit

Permalink
Install ESLint and fix recommended rules (closes date-fns#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jun 14, 2019
1 parent 611e866 commit 5c0fc04
Show file tree
Hide file tree
Showing 81 changed files with 739 additions and 236 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
/tmp
/examples/*/dist
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: ['eslint:recommended', 'prettier'],
parser: 'babel-eslint',
env: {
browser: true,
node: true,
es6: true
},
rules: {
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }]
}
}
5 changes: 5 additions & 0 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-console': 'off'
}
}
5 changes: 5 additions & 0 deletions docs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-console': 'off'
}
}
5 changes: 5 additions & 0 deletions examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-console': 'off'
}
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"@babel/plugin-transform-block-scoping": "^7.4.4",
"@babel/plugin-transform-modules-commonjs": "^7.4.4",
"babel-eslint": "^10.0.1",
"babel-loader": "8.0.6",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-preset-power-assert": "^3.0.0",
"cloc": "^2.2.0",
"coveralls": "^3.0.2",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"firebase": "^3.7.1",
"flow-bin": "0.84.0",
"fs-promise": "^1.0.0",
Expand Down
3 changes: 0 additions & 3 deletions scripts/.eslintrc

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'no-console': 'off'
}
}
4 changes: 2 additions & 2 deletions scripts/_lib/firebase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const firebase = require('firebase')
const {snakeCase} = require('lodash')
const { snakeCase } = require('lodash')

module.exports = {
getFirebaseDB
Expand All @@ -22,7 +22,7 @@ firebase.initializeApp({
databaseURL: firebaseDatabaseURL
})

function getFirebaseDB (db) {
function getFirebaseDB() {
return firebase
.auth()
.signInWithEmailAndPassword(firebaseEmail, firebasePassword)
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/_lib/typings/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function generateFlowTypings(fns, aliases, locales, constants) {
aliases.find(alias => alias.title === 'Locale')
)

fns.forEach((fn, index) => {
fns.forEach(fn => {
if (fn.isFPFn) {
generateFlowFPFnTyping(fn, aliasDeclarations)
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/_lib/typings/typeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function getTypeScriptInterfaceDefinition(fn) {
return `${title}${params}: ${returns}`
}

function generateTypescriptFnTyping(fn, aliasDeclarations) {
function generateTypescriptFnTyping(fn) {
const typingFile = formatTypeScriptFile`
import {${fn.title}} from 'date-fns'
export default ${fn.title}
Expand Down
6 changes: 3 additions & 3 deletions scripts/build/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function buildGroupsTemplate(groups) {
/**
* Returns promise to list of static docs with its contents.
*/
function getListOfStaticDocs(staticDocs) {
function getListOfStaticDocs() {
return Promise.all(
docsConfig.staticDocs.map(staticDoc => {
return fsp
Expand All @@ -159,7 +159,7 @@ function getListOfStaticDocs(staticDocs) {
/**
* Returns promise to list of shared docs with its contents.
*/
function generateSharedDocs(sharedDocs) {
function generateSharedDocs() {
const docs = docsConfig.sharedDocs
.map(
fn =>
Expand Down Expand Up @@ -329,7 +329,7 @@ function paramsToTree(dirtyParams) {
}, {})

return params
.map((param, index) => {
.map(param => {
const { name, isProperty } = param

const indexOfDot = name.indexOf('.')
Expand Down
8 changes: 4 additions & 4 deletions src/fp/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,15 @@ describe('FP functions', function() {
})

it('roundToNearestMinutesWithOptions', function() {
var result = fp.roundToNearestMinutesWithOptions({ nearestTo: 5 })(
const resultA = fp.roundToNearestMinutesWithOptions({ nearestTo: 5 })(
new Date(2014, 6 /* Jul */, 10, 12, 11, 34, 99)
)
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 10))
assert.deepEqual(resultA, new Date(2014, 6 /* Jul */, 10, 12, 10))

var result = fp.roundToNearestMinutesWithOptions({})(
const resultB = fp.roundToNearestMinutesWithOptions({})(
new Date(2014, 6 /* Jul */, 10, 12, 11, 34, 99)
)
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 12))
assert.deepEqual(resultB, new Date(2014, 6 /* Jul */, 10, 12, 12))
})

it('setDate', function() {
Expand Down
8 changes: 4 additions & 4 deletions src/locale/_lib/buildLocalizeFn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export default function buildLocalizeFn(args) {

var valuesArray
if (context === 'formatting' && args.formattingValues) {
var defaultWidth = args.defaultFormattingWidth || args.defaultWidth
var width = options.width ? String(options.width) : defaultWidth
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth
const width = options.width ? String(options.width) : defaultWidth
valuesArray =
args.formattingValues[width] || args.formattingValues[defaultWidth]
} else {
var defaultWidth = args.defaultWidth
var width = options.width ? String(options.width) : args.defaultWidth
const defaultWidth = args.defaultWidth
const width = options.width ? String(options.width) : args.defaultWidth
valuesArray = args.values[width] || args.values[defaultWidth]
}
var index = args.argumentCallback
Expand Down
2 changes: 1 addition & 1 deletion src/locale/ar-DZ/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative(token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/ar-SA/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative(token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/ar/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'L'
}

export default function formatRelative (token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/bg/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'L'
}

export default function formatRelative (token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/bn/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative (token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/ca/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var formatRelativeLocalePlural = {
other: 'P'
}

export default function formatRelative(token, date, baseDate, options) {
export default function formatRelative(token, date, _baseDate, _options) {
if (date.getUTCHours() !== 1) {
return formatRelativeLocalePlural[token]
}
Expand Down
13 changes: 1 addition & 12 deletions src/locale/ca/_lib/localize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,8 @@ var formattingDayPeriodValues = {
}
}

function ordinalNumber(dirtyNumber, dirtyOptions) {
function ordinalNumber(dirtyNumber, _dirtyOptions) {
var number = Number(dirtyNumber)

// If ordinal numbers depend on context, for example,
// if they are different for different grammatical genders,
// use `options.unit`:
//
var options = dirtyOptions || {}
var unit = String(options.unit)
//
// where `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear',
// 'day', 'hour', 'minute', 'second'

var rem100 = number % 100
if (rem100 > 20 || rem100 < 10) {
switch (rem100 % 10) {
Expand Down
2 changes: 1 addition & 1 deletion src/locale/cs/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'L'
}

export default function formatRelative (token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/da/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative(token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/de/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative (token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
44 changes: 39 additions & 5 deletions src/locale/de/_lib/localize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,49 @@ var quarterValues = {
// e.g. in Spanish language the weekdays and months should be in the lowercase.
var monthValues = {
narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
abbreviated: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
wide: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
abbreviated: [
'Jan',
'Feb',
'Mär',
'Apr',
'Mai',
'Jun',
'Jul',
'Aug',
'Sep',
'Okt',
'Nov',
'Dez'
],
wide: [
'Januar',
'Februar',
'März',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Dezember'
]
}

var dayValues = {
narrow: ['S', 'M', 'D', 'M', 'D', 'F', 'S'],
short: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
abbreviated: ['So.', 'Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.'],
wide: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag']
wide: [
'Sonntag',
'Montag',
'Dienstag',
'Mittwoch',
'Donnerstag',
'Freitag',
'Samstag'
]
}

// https://www.unicode.org/cldr/charts/32/summary/de.html#1881
Expand Down Expand Up @@ -95,7 +129,7 @@ var formattingDayPeriodValues = {
}
}

function ordinalNumber (dirtyNumber, dirtyOptions) {
function ordinalNumber(dirtyNumber, _dirtyOptions) {
var number = Number(dirtyNumber)

return number + '.'
Expand All @@ -112,7 +146,7 @@ var localize = {
quarter: buildLocalizeFn({
values: quarterValues,
defaultWidth: 'wide',
argumentCallback: function (quarter) {
argumentCallback: function(quarter) {
return Number(quarter) - 1
}
}),
Expand Down
2 changes: 1 addition & 1 deletion src/locale/el/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative(token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
2 changes: 1 addition & 1 deletion src/locale/en-US/_lib/formatRelative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ var formatRelativeLocale = {
other: 'P'
}

export default function formatRelative (token, date, baseDate, options) {
export default function formatRelative(token, _date, _baseDate, _options) {
return formatRelativeLocale[token]
}
Loading

0 comments on commit 5c0fc04

Please sign in to comment.