Skip to content

Commit 2718293

Browse files
committed
eslint cleanup
1 parent 6d3c7f1 commit 2718293

13 files changed

Lines changed: 53 additions & 79 deletions

.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module.exports = {
1717
ecmaVersion: 'latest',
1818
sourceType: 'module',
1919
},
20-
rules: {},
20+
rules: {
21+
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
22+
},
2123
plugins: ['jest'],
2224
};

lib/AppContext.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { createDataHarmonizerContainer, createDataHarmonizerTab } from '../web';
1111
import { getExportFormats } from 'schemas';
1212
import { range as arrayRange } from 'lodash';
1313
import { deepMerge } from '../lib/utils/objects';
14-
import Validator from './Validator';
1514
import i18next from 'i18next';
1615

1716
import {SchemaEditor} from './SchemaEditor';
@@ -38,7 +37,7 @@ export default class AppContext {
3837
console.log("this should only be done once")
3938
// THIS WAS $(document), but that was causing haywire issues with Handsontable!!!!
4039
// Each tab was requiring a double click to fully render its table!!!
41-
$('#data-harmonizer-tabs').on('dhTabChange', (event, class_name) => {
40+
$('#data-harmonizer-tabs').on('dhTabChange', () => {
4241
//if (this.getCurrentDataHarmonizer() !== class_name) {
4342
//this.tabChange(class_name);
4443
//}
@@ -309,7 +308,7 @@ export default class AppContext {
309308
// .inherits[enum1 name, enum2 name, ... , this enum], merging each in order
310309
// such that permissible value labels, descriptions and mappings can be
311310
// overwritten. See https://linkml.io/linkml-model/latest/docs/inherits/
312-
Object.entries(schema.enums || {}).forEach(([enum_name, enum_obj]) => {
311+
Object.entries(schema.enums || {}).forEach(([, enum_obj]) => {
313312
if (enum_obj.inherits) {
314313
const values = {};
315314
enum_obj.inherits.forEach(inherit_enum_name => {
@@ -377,7 +376,6 @@ export default class AppContext {
377376
const dhId = `data-harmonizer-grid-${index}`;
378377
const tab_label = class_obj.title ? class_obj.title : class_name;
379378
const dhTab = createDataHarmonizerTab(dhId, tab_label, class_name, tooltip, index === 0);
380-
const self = this;
381379

382380
// Future: Change createDataHarmonizerTab() to return jquery dom element id?
383381
dhTab.addEventListener('click', (event) => {
@@ -830,7 +828,6 @@ export default class AppContext {
830828
*/
831829
stringifyNestedVocabulary(vocab_list) {
832830
let ret = [];
833-
let stack = [];
834831
for (const pointer in vocab_list) {
835832
let choice = vocab_list[pointer];
836833
this.setExportField(choice, false); // Move elsewhere?
@@ -1112,14 +1109,14 @@ export default class AppContext {
11121109
// First pass establishes basic attributes so 2nd pass references to
11131110
// .parent or .child don't matter, i.e. classes can be processed in
11141111
// any order.
1115-
Object.entries(schema.classes).forEach(([class_name, class_obj]) => {
1112+
Object.entries(schema.classes).forEach(([class_name]) => {
11161113
if (class_name != 'Container' && class_name != 'dh_interface') {
11171114
relations[class_name] = {
11181115
parent: {},
11191116
child: {},
11201117
dependent_slots: {},
11211118
foreign_key_count: 0,
1122-
target_slots: {},
1119+
target_slots: {},
11231120
unique_key_slots: {}
11241121
};
11251122
}
@@ -1286,7 +1283,6 @@ export default class AppContext {
12861283
let class_dependents = this.relations[class_name].dependents;
12871284
for (let [dependent_name] of class_dependents.entries()) {
12881285
this.setDHTabStatus(dependent_name);
1289-
const dh = this.dhs[dependent_name];
12901286
};
12911287
};
12921288

@@ -1441,7 +1437,7 @@ export default class AppContext {
14411437
* @param {Object} changes dictionary pertaining to a particular dh row's slots.
14421438
* @return {Object} this.dependent_rows updated table of given start_name class's foreign and other keys and their current and changed values
14431439
*/
1444-
crudGetDependentRows(start_name, skippable=false, changes = {}) {
1440+
crudGetDependentRows(start_name, _skippable=false, changes = {}) {
14451441
// Changes only apply to start_name class; all dependents should "see" them
14461442
// only via dependent_rows foreign key values.
14471443
let [key_vals, fkey_vals, fkey_status] =
@@ -1450,8 +1446,8 @@ export default class AppContext {
14501446
// Changes may include any key slots (not just foreign keys), but other
14511447
// slots are ignored.
14521448
let changed_keys = Object.fromEntries(Object.entries(key_vals)
1453-
.filter(([slot_name, value]) => changes.hasOwnProperty(slot_name))
1454-
.map(([slot_name, value]) => ([slot_name, changes[slot_name].value]))
1449+
.filter(([slot_name]) => changes.hasOwnProperty(slot_name))
1450+
.map(([slot_name]) => ([slot_name, changes[slot_name].value]))
14551451
);
14561452

14571453
this.dependent_rows.set(start_name, {
@@ -1549,7 +1545,7 @@ export default class AppContext {
15491545
// are included in the cascade report even when only the top-level
15501546
// ancestor (e.g. Schema) is selected.
15511547
let search_vals = Object.fromEntries(
1552-
Object.entries(fkey_vals).filter(([k, v]) => v !== null)
1548+
Object.entries(fkey_vals).filter(([, v]) => v !== null)
15531549
);
15541550
let rows = this.crudFindAllRowsByKeyVals(class_name, search_vals);
15551551
if (rows.length) {
@@ -1594,7 +1590,7 @@ export default class AppContext {
15941590
* @return {Object} changed_key_vals by slot_name of key values that are changing (and need to be updated)
15951591
* @return {Boolean} key_status = integer
15961592
*/
1597-
crudGetDependentKeyVals(class_name, changes) {
1593+
crudGetDependentKeyVals(class_name, _changes) {
15981594
const class_dh = this.dhs[class_name];
15991595
let fkey_vals = {};
16001596
let key_vals = {};
@@ -1814,8 +1810,8 @@ export default class AppContext {
18141810
// controlled by dependent CRUD create and update actions.
18151811
crudMakeForeignKeysReadOnly(dh, class_name) {
18161812
Object.entries(this.crudGetParents(class_name)).forEach(
1817-
([parent_name, parent]) => {
1818-
Object.entries(parent).forEach(([slot_name, foreign_name]) => {
1813+
([, parent]) => {
1814+
Object.entries(parent).forEach(([slot_name]) => {
18191815
let col = dh.slot_name_to_column[slot_name];
18201816
if (dh.slots[col].required) {
18211817
dh.updateColumnSettings(col, { readOnly: true });
@@ -1848,7 +1844,7 @@ export default class AppContext {
18481844
let changed = false;
18491845
let complete = Object.entries(key_obj.unique_key_slots)
18501846
// If every slot has a value, then the whole key is complete.
1851-
.every(([index, slot_name]) => {
1847+
.every(([, slot_name]) => {
18521848
// Key has a changed value (incl. null?), so update it.
18531849
if (slot_name in changes) {
18541850
changed = true; // signals that a change has been made to key.

lib/DataHarmonizer.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import '@selectize/selectize';
22
import Handsontable from 'handsontable';
3-
import SheetClip from 'sheetclip';
43
import $ from 'jquery';
5-
6-
import YAML from 'yaml';//#{ parse, stringify } from 'yaml'
7-
//import {strOptions} from 'yaml/types'
8-
//strOptions.fold.lineWidth = 0; // Prevents yaml long strings from wrapping.
9-
//strOptions.fold.defaultStringType = 'QUOTE_DOUBLE'
10-
//YAML.scalarOptions.str.defaultType = 'QUOTE_SINGLE'
11-
//scalarOptions.str.defaultType = 'QUOTE_SINGLE'
124
import i18next from 'i18next';
135
import { renderContent, urlToClickableAnchor } from './utils/content';
146
import { isEmpty, rowIsEmpty, isEmptyUnitVal } from '../lib/utils/general';
157

168
import {
179
changeCase,
1810
formatMultivaluedValue,
19-
JSON_SCHEMA_FORMAT,
2011
MULTIVALUED_DELIMITER,
2112
parseMultivaluedValue
2213
} from './utils/fields';
@@ -197,7 +188,7 @@ class DataHarmonizer {
197188
// This catches case where user dblclicks on column label, and just wants
198189
// to see help info. Without this check, column is selected first, which
199190
// blows away row selection.
200-
Handsontable.hooks.add('beforeOnCellMouseDown', function(event, coords, element) {
191+
Handsontable.hooks.add('beforeOnCellMouseDown', function(event, coords) {
201192
// Check if a column header was clicked
202193
if (coords.row < 0 && event.srcElement.classList.contains('secondary-header-text')) {
203194
event.stopImmediatePropagation(); // Prevent default behavior and bubbling
@@ -291,7 +282,7 @@ class DataHarmonizer {
291282
},
292283
row_above: {
293284
name: 'Insert row above',
294-
callback (action, selection, event) {
285+
callback () {
295286
// Ensuring that rows inserted into foreign-key dependent tables
296287
// take in the appropriate focused foreign-key values on creation.
297288
self.addRows('insert_row_above', 1, self.hot.getSelected()[0][0]);
@@ -383,14 +374,14 @@ class DataHarmonizer {
383374
}
384375
},
385376
// FIXING ISSUE WHERE HIGHLIGHTED FIELDS AREN'T IN GOOD SHAPE AFTER SORTING.
386-
afterColumnSort: function (currentSortConfig, destinationSortConfigs) {
377+
afterColumnSort: function () {
387378
// if (self.schema.name === 'DH_LinkML' && self.template_name === 'Slot') {
388379
// // Somehow on first call the this.context.dhs doesnt exist yet, so passing self.
389380
// self.schemaSlotClassView(self);
390381
// }
391382
},
392383

393-
afterFilter: function (filters) {
384+
afterFilter: function () {
394385
// column: 0, conditions: ('cancogen_covid-19', "eq", [], operation: "conjunction"
395386

396387
},
@@ -667,7 +658,6 @@ class DataHarmonizer {
667658
// self.current_selection[0] === null ||
668659
// self.current_selection[1] === null ||
669660
const row_change = !(self.current_selection[0] === row);
670-
const column_change = !(self.current_selection[1] === column);
671661
self.current_selection = [row, column, row2, column2];
672662
if (column < 0) column = 0;
673663
if (row < 0) row = 0;
@@ -752,7 +742,7 @@ class DataHarmonizer {
752742
// Handsontable search extension for future use (fixed their example).
753743
// DH search defaults to any substring match (See hot_settings above).
754744
// Function below provides string exact match (incl. case sensitivity)
755-
searchMatchCriteria (queryStr, value, metadata) {
745+
searchMatchCriteria (queryStr, value) {
756746
return queryStr.toString() === value?.toString();
757747
}
758748

@@ -817,7 +807,7 @@ class DataHarmonizer {
817807

818808
if (class_name != dependent_name && dependent_rep.count) {
819809
let fkey_vals = Object.entries(dependent_rep.fkey_vals)
820-
.filter(([x, y]) => y != null)
810+
.filter(([, y]) => y != null)
821811
.join('\n ')
822812
.replaceAll(',', ': ');
823813
change_message += `\n - ${dependent_rep.count} ${dependent_name} record(s) with key:\n ${fkey_vals}`;
@@ -832,7 +822,7 @@ class DataHarmonizer {
832822
// UPDATED: using .unique_key_slots rather than .target_slots
833823
const class_relations = this.context.relations[class_name];
834824
for (const key in class_relations.unique_key_slots) { //, ...class_relations.target_slots]
835-
for (const [row, change] of Object.entries(changes)) {
825+
for (const [, change] of Object.entries(changes)) {
836826
//console.log("CHANGE",class_name, "change", change,"KEY", key, row)
837827
if (key in change) {
838828
return true;
@@ -1389,7 +1379,7 @@ class DataHarmonizer {
13891379
// attribute name (usually plural) as spreadsheet tab name.
13901380
const match = Object.entries(this.schema.classes['Container'].attributes)
13911381
// cls_key = name = usually plural container attribute name
1392-
.find(([cls_key, { name, range }]) => range == this.template.name);
1382+
.find(([, { range }]) => range == this.template.name);
13931383
if (match) {
13941384
sheet_name = match[0];
13951385
}
@@ -1645,7 +1635,7 @@ class DataHarmonizer {
16451635
items: dh.getDataAtCell(row, col)?.split(MULTIVALUED_DELIMITER) || [],
16461636

16471637
hideSelected: false,
1648-
onChange: function(value) {
1638+
onChange: function() {
16491639
this.focus(); // required for cursor
16501640
},
16511641
/*

lib/FieldMapper.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@
5757
import $ from 'jquery';
5858
import {readBrowserDHSettings, saveBrowserDHSettings, clearDH} from './Toolbar';
5959
import YAML from 'yaml';
60-
import { updateSheetRange } from '../lib/utils/files';
6160
// dataObjectToArray no longer used (JSON rows pre-converted to arrays in openJSONDataFile)
6261
// import { dataObjectToArray } from '../lib/utils/fields';
63-
import { utils as XlsxUtils } from 'xlsx/xlsx.js';
6462

6563
// A call like fm = new FieldMapper().bind(this), provides caller environment
6664
// variables
@@ -90,7 +88,7 @@ export class FieldMapper {
9088
dh_settings.schema ??= {};
9189
if (!(schema.name in dh_settings.schema))
9290
dh_settings.schema[schema.name] = {};
93-
Object.entries(dh_settings.schema[schema.name]).forEach(([name, value]) => {
91+
Object.entries(dh_settings.schema[schema.name]).forEach(([name]) => {
9492
const newOption = new Option(name, name);
9593
$('#field-mapping-select').append(newOption);
9694
});
@@ -114,11 +112,11 @@ export class FieldMapper {
114112
* - copy it to field-mapping-name
115113
* - implement it in combined drag & drop table list of data file fields.
116114
*/
117-
$('#field-mapping-select').off('change').on('change', function(e) {
115+
$('#field-mapping-select').off('change').on('change', function() {
118116
const profile_name = $('#field-mapping-select').val();
119117
$('#field-mapping-delete-btn').prop('disabled', profile_name == '');
120118
if (profile_name.length > 0) {
121-
const [dh_settings, profile] = self.getProfile(profile_name);
119+
const [, profile] =self.getProfile(profile_name);
122120
self.renderFieldMappingProfile(profile_name, profile);
123121
}
124122
});
@@ -150,7 +148,7 @@ export class FieldMapper {
150148
$('#field-mapping-name').val(profile_name)
151149
if (profile_name) {
152150
self.updateProfileMapping(profile_name); // profile object updated in-situ.
153-
const [dh_settings, profile] = self.getProfile(profile_name);
151+
const [, profile] =self.getProfile(profile_name);
154152
self.renderFieldMappingProfile(profile_name, profile);
155153
}
156154
else {
@@ -194,7 +192,7 @@ export class FieldMapper {
194192
const map_obj = mappings?.tables[template_name];
195193

196194
// Process each row of data
197-
Object.entries(data_table).forEach(([row_ptr, row]) => {
195+
Object.entries(data_table).forEach(([, row]) => {
198196
const new_row = [];
199197

200198
// Make full dh row, and add as many exact matches from incomming data
@@ -211,7 +209,7 @@ export class FieldMapper {
211209
// Might not be any rules for a table that is missing some fields but
212210
// user has not supplied any mappings.
213211
// Overwrite any (empty) fields with user-defined column mapping.
214-
Object.entries(map_obj?.map || {}).forEach(([ptr, mapping]) => {
212+
Object.entries(map_obj?.map || {}).forEach(([, mapping]) => {
215213
const col_from = data_field_to_col[mapping.from];
216214
const col_to = dh.slot_name_to_column[mapping.to];
217215
new_row[col_to] = row[col_from];
@@ -307,7 +305,7 @@ export class FieldMapper {
307305
// Loop through each section
308306
let done_data_row = {};
309307
Object.entries(dh.sections)
310-
.forEach(([i, section]) => {
308+
.forEach(([, section]) => {
311309

312310
// Adding template and section to make easier to search and replace content.
313311
html += `
@@ -321,7 +319,7 @@ export class FieldMapper {
321319
// Starting at -1 so the first pre-match check begins at data column 0.
322320
let last_shown_data_row = -1;
323321

324-
Object.entries(section.children).forEach(([section_slot_row, slot]) => {
322+
Object.entries(section.children).forEach(([, slot]) => {
325323

326324
if (slot_matches[slot_row] >= 0) {
327325
const data_row = slot_matches[slot_row];
@@ -495,7 +493,7 @@ export class FieldMapper {
495493
dh_settings.schema = {};
496494
if (!(schema.name in dh_settings.schema))
497495
dh_settings.schema[schema.name] = {};
498-
Object.entries(dh_settings.schema[schema.name]).forEach(([name, value]) => {
496+
Object.entries(dh_settings.schema[schema.name]).forEach(([name]) => {
499497
const newOption = new Option(name, name);
500498
$('#field-mapping-select').append(newOption);
501499
});
@@ -577,13 +575,13 @@ export class FieldMapper {
577575
// Apply a saved mapping profile to the current field-mapping display.
578576
// Uses data-slot-name and data-field-name attributes for reliable matching.
579577
applyFieldMapping(profile_name) {
580-
const [dh_settings, profile] = this.getProfile(profile_name);
578+
const [, profile] =this.getProfile(profile_name);
581579

582580
Object.entries(profile.tables || {}).forEach(([table_name, table_obj]) => {
583581

584582
// Doing table by table; otherwise identical field names in different
585583
// tables lead to garbled rule implementation.
586-
Object.entries(table_obj?.map || {}).forEach(([index, mapping]) => {
584+
Object.entries(table_obj?.map || {}).forEach(([, mapping]) => {
587585
// Find the unmatched slot TD by data-slot-name attribute.
588586
const schema_slot_td = $(
589587
`table#field-mapping-table tbody[data-table="${table_name}"] > tr.field-mismatch > td:first-child[data-slot-name="${mapping.to}"]`

0 commit comments

Comments
 (0)