-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #543 from Gapminder/feat-inconsistent-synonym-key
feat(new rule): provide new rule INCONSISTENT_SYNONYM_KEY
- Loading branch information
Showing
15 changed files
with
3,889 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { endsWith, isEmpty } from 'lodash'; | ||
import { INCONSISTENT_SYNONYM_KEY } from '../registry'; | ||
import { DdfDataSet } from '../../ddf-definitions/ddf-data-set'; | ||
import { Issue } from '../issue'; | ||
|
||
export const rule = { | ||
rule: (ddfDataSet: DdfDataSet) => { | ||
const issues = []; | ||
const synonymsData = ddfDataSet.getSynonym().getAllData(); | ||
|
||
for (const record of synonymsData) { | ||
const resource = ddfDataSet.getDataPackageResources().find(resource => endsWith(record.$$source, resource.path)); | ||
const primaryKey = resource.schema.primaryKey; | ||
const undefinedKeyParts = []; | ||
|
||
for (const partOfPrimaryKey of primaryKey) { | ||
if (isEmpty(record[partOfPrimaryKey])) { | ||
undefinedKeyParts.push(partOfPrimaryKey); | ||
} | ||
} | ||
|
||
if (!isEmpty(undefinedKeyParts)) { | ||
issues.push(new Issue(INCONSISTENT_SYNONYM_KEY) | ||
.setPath(record.$$source) | ||
.setData({line: record.$$lineNumber, undefinedKeyParts})); | ||
} | ||
} | ||
|
||
return issues; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.