Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrelsford committed Mar 17, 2022
0 parents commit 74f9c29
Show file tree
Hide file tree
Showing 15 changed files with 5,360 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.parcel-cache
44 changes: 44 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Copyright (c) 2021, Stamen Design <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

-------------------------------------------------------------------------------

Contains code from mapbox-gl-js v1.13 and earlier

Version v1.13 of mapbox-gl-js and earlier are licensed under a BSD-3-Clause license

Copyright (c) 2020, Mapbox
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Mapbox GL JS nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# mapbox-gl-style-linter

Lint Mapbox GL styles.

## Why? Doesn't the style spec do this?

Yes, the style spec has [gl-style-validate](https://github.com/mapbox/mapbox-gl-js/blob/83b8d8fb690a9fd1a9eef558d425725679287887/src/style-spec/bin/gl-style-validate), but this module solves two issues:

1. The style spec tool uses an older version of Node, so it can be difficult to execute in projects that use newer versions.
2. The style spec tool does not find every error you might want to find. For example, the style spec tool does not raise errors for `paint` or `layout` property ids at the top level of a layer.

This tool takes the same inputs and creates compatible outputs to the style spec's `gl-style-validate` tool.

## Usage

1. Install.
2. Execute on one or more styles:
```bash
mapbox-gl-style-lint styles/*.json
```

## Development

1. Clone this repo.
2. Install dependencies (`yarn install`).
3. Start build tool (`yarn watch`).
4. Start the test suite (`yarn test`).
5. Make changes in `src`.

51 changes: 51 additions & 0 deletions bin/mapbox-gl-style-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node

const fs = require('fs');
const jsonlint = require('@mapbox/jsonlint-lines-primitives');

const { lint } = require('../dist/main');

const parseArguments = argv => {
const args = argv.slice(2);
const filepaths = [];

args.forEach(v => {
filepaths.push(v);
});

if (!filepaths.length) {
console.error(`Could not find filepaths. Exiting.
Usage: ${process.argv[1]} files...`);
process.exit(1);
}

return { filepaths };
}

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

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

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

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

const errors = lint(style);

if (errors) {
outputErrors(file, errors);
process.exit(1);
}
});
});
178 changes: 178 additions & 0 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74f9c29

Please sign in to comment.