Skip to content

Commit

Permalink
Lint all style paths (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
aparlato authored Apr 14, 2022
1 parent 19191c9 commit 0ed9f65
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions bin/mapbox-gl-style-lint
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,37 @@ Usage: ${process.argv[1]} files...`);
}

return { filepaths };
}
};

const outputErrors = (file, errors) => {
errors.forEach(e => {
console.log(`${file}:${e.line}: ${e.message}`);
});
}
const getErrorOutput = (file, error) => {
return `${file}:${error.line}: ${error.message}`;
};

const { filepaths } = parseArguments(process.argv);

filepaths.forEach(file => {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.error(err);
process.exit(1);
}
let errors = [];

filepaths.map(file => {
let style;
try {
style = fs.readFileSync(file, 'utf8');
} catch (err) {
console.error(err);
process.exit(1);
}

// Use jsonlint to get line numbers
const style = jsonlint.parse(data);
// Use jsonlint to get line numbers
style = jsonlint.parse(style);

const errors = lint(style);
let styleErrors = lint(style);

if (errors) {
outputErrors(file, errors);
process.exit(1);
}
});
if (styleErrors) {
styleErrors = styleErrors.map(e => getErrorOutput(file, e));
errors = errors.concat(styleErrors);
}
});

if (errors.length) {
errors.forEach(e => console.log(e));
process.exit(1);
}

0 comments on commit 0ed9f65

Please sign in to comment.