Skip to content

Commit

Permalink
add eslint unicorn and first rule to use includes (covidatlas#652)
Browse files Browse the repository at this point in the history
* add eslint unicorn and first rule to use includes

* casing
  • Loading branch information
camjc authored Apr 8, 2020
1 parent 43c4640 commit 646dc96
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 34 deletions.
22 changes: 16 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"extends": [
"airbnb-base",
"plugin:prettier/recommended"
],
"plugins": [
"unicorn"
],
"ignorePatterns": [
"node_modules/",
"dist/",
Expand All @@ -16,21 +22,25 @@
"rules": {
"consistent-return": "off",
"func-names": "off",
"import/extensions": ["error", "ignorePackages"],
"import/no-named-as-default": "off",
"import/extensions": [
"error",
"ignorePackages"
],
"guard-for-in": "off",
"import/no-named-as-default-member": "off",
"import/no-named-as-default": "off",
"max-classes-per-file": "off",
"no-async-promise-executor": "off",
"no-await-in-loop": "off",
"no-console": "off",
"no-continue": "off",
"no-labels": "off",
"no-loop-func": "off",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-restricted-syntax": "off",
"no-shadow": "off",
"no-underscore-dangle": "off",
"no-loop-func": "off",
"max-classes-per-file": "off",
"guard-for-in": "off"
"unicorn/prefer-includes": "error"
}
}
2 changes: 1 addition & 1 deletion docs/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ To add test coverage for a scraper, you only need to provide test assets; no new
- File name: raw_githubusercontent_com_opencovid19_fr_data_master_dist_chiffres_cles.csv

- Add a file named `expected.json` containing the array of values that the scraper is expected to
return. (Leave out any geojson `features` properties.)
return. (Leave out any GeoJSON `features` properties.)

For sources that have a time series, the `expected.json` file represents the latest result in the
sample response provided. You can additionally test the return value for a specific date by adding
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-unicorn": "^18.0.1",
"gh-pages": "^2.2.0",
"husky": "^4.2.3",
"lint-staged": "^10.0.8",
Expand Down
2 changes: 1 addition & 1 deletion site/crossCheckReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function showCrossCheckReport() {
fetch.json('report.json', function(report) {
reportContainer.innerHTML = generateCrossCheckPage(report.scrape.crosscheckReports, report.date);

if (window.location.hash.indexOf(':') !== -1) {
if (window.location.hash.includes(':')) {
document.getElementById(window.location.hash.substr(1)).scrollIntoView({
behavior: 'smooth',
block: 'start'
Expand Down
2 changes: 1 addition & 1 deletion site/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function showSources() {
for (let i = 0; i < ratings.length; i++) {
list.insertAdjacentHTML('beforeend', ratingTemplate(ratings[i], i));
}
if (window.location.hash.indexOf(':') !== -1) {
if (window.location.hash.includes(':')) {
document.getElementById(window.location.hash.substr(1)).scrollIntoView({
behavior: 'smooth',
block: 'start'
Expand Down
4 changes: 2 additions & 2 deletions src/events/processor/dedupe-locations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ function addCrosscheckReport(crosscheckReports, locationName, crosscheckResult,
const discrepancies = [];
const agreements = [];
for (const prop of numericalValues) {
if (report.discrepancies.indexOf(prop) > -1 || crosscheckResult[0].indexOf(prop) > -1) {
if (report.discrepancies.includes(prop) || crosscheckResult[0].includes(prop)) {
discrepancies.push(prop);
} else if (report.agreements.indexOf(prop) > -1 || crosscheckResult[1].indexOf(prop) > -1) {
} else if (report.agreements.includes(prop) || crosscheckResult[1].includes(prop)) {
agreements.push(prop);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/events/processor/find-features/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const props = [
];

const locationTransforms = {
// 🇭🇰
// ��
'Hong Kong': location => {
location.country = 'HKG';
delete location.state;
Expand Down Expand Up @@ -311,7 +311,7 @@ const generateFeatures = ({ locations, report, options, sourceRatings }) => {

// Match alternate names
// No known location, but might be useful in the future
if (feature.properties.alt && feature.properties.alt.split('|').indexOf(state) !== -1) {
if (feature.properties.alt && feature.properties.alt.split('|').includes(state)) {
found = true;
storeFeature(feature, location);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lib/geography/country-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getLevelData = async level => {

export const getLocationData = async id => {
// Return an array of aggregated features
if (id.indexOf('+') !== -1) {
if (id.includes('+')) {
const parts = id.split('+');
const data = await Promise.all(parts.map(getLocationData));
return data;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lib/geography/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function generateMultiCountyFeature(counties, properties) {
const polygons = [];
const features = [];
for (const countyFeature of countyGeoJSON.features) {
if (counties.indexOf(countyFeature.properties.name) !== -1) {
if (counties.includes(countyFeature.properties.name)) {
features.push(countyFeature.properties.name);
polygons.push(turf.feature(countyFeature.geometry));
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const transposeTimeseries = function(timeseriesByLocation) {
let allDates = [];
for (const [locationName, location] of Object.entries(timeseriesByLocation)) {
for (const [date] of Object.entries(location.dates)) {
if (allDates.indexOf(date) === -1) {
if (!allDates.includes(date)) {
allDates.push(date);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/scrapers/US/CA/santa-barbara-county.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const scraper = {

let $table = $('td:contains("City or Area")').closest('table');
let data = $table.parsetable(false, false, true);
if (data[1][0].indexOf('Confirmed Cases') === -1) {
if (!data[1][0].includes('Confirmed Cases')) {
throw new Error('Unknown headers in html table');
}
let lastRow = data[0].length - 1;
Expand All @@ -46,7 +46,7 @@ const scraper = {

$table = $('td:contains("Testing Status")').closest('table');
data = $table.parsetable(false, false, true);
if (data[1][0].indexOf('Total') === -1) {
if (!data[1][0].includes('Total')) {
throw new Error('Unknown headers in html table');
}
lastRow = data[0].length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/CO/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const scraper = {
if (visitorInfo !== null && visitorInfo.length === 3) {
const county = `${visitorInfo[1]} County`;
const cases = visitorInfo[2];
if (county.indexOf('information') === -1) {
if (!county.includes('information')) {
const data = {
county: geography.addCounty(parse.string(county)),
cases: parse.number(cases)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/HI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const scraper = {
.find('dd');
$list.each((index, row) => {
const text = $(row).text();
if (text.indexOf('County') === -1) {
if (!text.includes('County')) {
return;
}
const pieces = text.split(' ');
Expand Down
4 changes: 2 additions & 2 deletions src/shared/scrapers/US/KS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const scraper = {

const cases1 = data[1];

if (this._counties.indexOf(countyName1) !== -1) {
if (this._counties.includes(countyName1)) {
counties.push({
county: countyName1,
cases: parse.number(cases1)
Expand All @@ -173,7 +173,7 @@ const scraper = {
const countyName2 = geography.addCounty(data[2]);
const cases2 = data[3];

if (this._counties.indexOf(countyName2) !== -1) {
if (this._counties.includes(countyName2)) {
counties.push({
county: countyName2,
cases: parse.number(cases2)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/MO/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const scraper = {
_getCountyName(countyName) {
countyName = this._countyMap[countyName] || countyName;

if (countyName.toUpperCase().indexOf(' CITY') === -1) {
if (!countyName.toUpperCase().includes(' CITY')) {
countyName = geography.addCounty(countyName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/ND/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const scraper = {
continue;
}
county = geography.addCounty(county);
if (this._counties.indexOf(county) === -1) {
if (!this._counties.includes(county)) {
console.log(` ⚠️ Unknown county in table: "${county}"`);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/NE/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const scraper = {
county = 'Douglas County';
}

if (this._counties.indexOf(county) !== -1) {
if (this._counties.includes(county)) {
counties.push({
county,
cases
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/OH/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const scraper = {
// This hack lets me determine the header value for sure
const countyCol = Object.keys(rows[0])[0];
// Make sure it's actually the County header
if (countyCol.indexOf('County') === -1) {
if (!countyCol.includes('County')) {
throw new Error('First column of csv is no longer county!');
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/RI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const scraper = {
const cases = parse.number(row[caseHdr]);

// skip the last updated timestamp row
if (county.indexOf('last updated') !== -1) {
if (county.includes('last updated')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/TN/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const scraper = {
rec.deaths = deaths;
}

if (this._counties.indexOf(county) === -1) {
if (!this._counties.includes(county)) {
unassignedCounty.cases += cases;
unassignedCounty.tested += tested;
if (hasDeaths) {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/UT/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const scraper = {
const $tr = $(tr);
const county = parse.string($tr.find('td:first-child').text());
const cases = parse.number($tr.find('td:last-child').text());
if (index > 0 && county.indexOf('Non-Utah') === -1) {
if (index > 0 && !county.includes('Non-Utah')) {
this._pushCounty(counties, county, cases);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/shared/scrapers/US/WV/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const scraper = {
const heading = 'CONFIRMED CASES PER COUNTY:';
for (const sec of sections) {
for (const vc of sec.visualContainers) {
if (vc.config.indexOf(heading) !== -1) {
if (vc.config.includes(heading)) {
const config = JSON.parse(vc.config);
let { textRuns } = config.singleVisual.objects.general[0].properties.paragraphs[0];
textRuns = textRuns.map(tr => parse.string(tr.value));
Expand Down
2 changes: 1 addition & 1 deletion src/shared/timeseries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function stripInfo(location) {
function stripCases(location) {
const newLocation = {};
for (const prop in location) {
if (caseDataProps.indexOf(prop) === -1) {
if (!caseDataProps.includes(prop)) {
newLocation[prop] = location[prop];
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/mapJHUCounties.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function findNameMapping() {

// eslint-disable-next-line no-labels
locationLoop: for (const location of jhuData) {
if (!location[STATE] || location[STATE].indexOf(',') === -1) {
if (!location[STATE] || !location[STATE].includes(',')) {
continue;
}

Expand Down
Loading

0 comments on commit 646dc96

Please sign in to comment.