Skip to content

Commit

Permalink
Merge pull request #20 from LiamAttClarke/chore/linter-config
Browse files Browse the repository at this point in the history
chore: adjust linter config
  • Loading branch information
LiamAttClarke authored Nov 3, 2024
2 parents 238be54 + 9afe72c commit 6609910
Show file tree
Hide file tree
Showing 74 changed files with 9,022 additions and 9,581 deletions.
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[*.{json,js,ts,html,css}]
indent_style = space
indent_size = 2
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
demo/main-bundle.js
dist/*
docs/*
.eslintrc.js
91 changes: 59 additions & 32 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
const isProduction = process.env.NODE_ENV === 'production';
const isProduction = process.env.NODE_ENV === "production";

module.exports = {
root: true,
env: {
node: true,
browser: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
ecmaVersion: 2020,
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts', '.d.ts'],
paths: ['node_modules/', 'node_modules/@types/'],
}
}
},
extends: [
'plugin:@typescript-eslint/recommended',
'airbnb-typescript/base',
],
plugins: [
'@typescript-eslint',
],
rules: {
'no-console': isProduction ? 'error' : 'warn',
'import/extensions': 'off',
'@typescript-eslint/type-annotation-spacing': 2,
}
root: true,
env: {
node: true,
browser: true
},
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
sourceType: "module",
ecmaVersion: 2020,
},
settings: {
"import/resolver": {
node: {
extensions: [".js", ".ts", ".d.ts"],
paths: ["node_modules/", "node_modules/@types/"],
}
}
},
extends: [
"plugin:@typescript-eslint/recommended",
"google",
],
plugins: [
"@typescript-eslint",
],
rules: {
"no-console": isProduction ? 2 : 1,
"import/extensions": 0,
"@typescript-eslint/type-annotation-spacing": 2,
"indent": ["error", 4],
"max-len": ["error", 100],
"quotes": ["error", "double"],
"operator-linebreak": [2, "before"],
"require-jsdoc": 0,
"object-curly-spacing": [2, "always"],
"valid-jsdoc": 0,
},
overrides: [
{
files: [
"bin/**/*.js",
"demo/**/*.js",
],
rules: {
"@typescript-eslint/no-var-requires": 0,
"no-console": 0,
}
},
{
files: [
"tests/**/*",
],
rules: {
"max-len": 0
}
}
]
};
89 changes: 46 additions & 43 deletions bin/svg-plotter.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,90 @@
#!/usr/bin/env node

const commander = require('commander');
const fs = require('fs');
const path = require('path');
const { convertSVG } = require('../dist');
const commander = require("commander");
const fs = require("fs");
const path = require("path");
const { convertSVG } = require("../dist");

commander
.version('0.0.0')
.usage('<input> [outputPath] [options]')
.option('-c, --center [center]', 'Geographic coordinate to center the SVG geometry around. (default: 0,0)')
.option('-w, --width [width]', 'Width in metres (default: 1000e3 ie. 1000km)')
.option('-b, --bearing [bearing]', 'Angle in degrees to rotate geometry clockwise around it\'s center. (default: 0)')
.option('-t, --subdivide-threshold [subdivideThreshold]', 'Angle in degrees at which to subdivide curves. Decrease this number for smoother curves. (Default: 5)')
.option('-p, --pretty', 'Pretty print output')
.parse(process.argv);
.version("0.0.0")
.usage("<input> [outputPath] [options]")
// eslint-disable-next-line max-len
.option("-c, --center [center]", "Geographic coordinate to center the SVG geometry around. (default: 0,0)")
.option("-w, --width [width]", "Width in metres (default: 1000e3 ie. 1000km)")
// eslint-disable-next-line max-len
.option("-b, --bearing [bearing]", "Angle in degrees to rotate geometry clockwise around it's center. (default: 0)")
// eslint-disable-next-line max-len
.option("-t, --subdivide-threshold [subdivideThreshold]", "Angle in degrees at which to subdivide curves. Decrease this number for smoother curves. (Default: 5)")
.option("-p, --pretty", "Pretty print output")
.parse(process.argv);

const options = commander.opts();

// Validate arguments

if (commander.args.length < 1) {
console.error('No input file specified.');
process.exit(1);
console.error("No input file specified.");
process.exit(1);
}

if (!fs.statSync(commander.args[0]).isFile() || path.extname(commander.args[0]) !== '.svg') {
console.error('Input argument must be an SVG file.');
process.exit(1);
if (!fs.statSync(commander.args[0]).isFile() || path.extname(commander.args[0]) !== ".svg") {
console.error("Input argument must be an SVG file.");
process.exit(1);
}

if (options.center && !options.center.match(/(\-)?\d+(\.\d+)?\(\-)?\d+(\.\d+)?/)) {
console.error('\'center\' must be in the form: {latitude},{longitude}');
console.error("'center' must be in the form: {latitude},{longitude}");
}

if (options.width) {
const width = parseFloat(options.width);
if (!width || width <= 0) {
console.error('\'scale\' must be greater than zero.');
process.exit(1);
}
const width = parseFloat(options.width);
if (!width || width <= 0) {
console.error("'scale' must be greater than zero.");
process.exit(1);
}
}

if (options.subdivideThreshold && parseFloat(options.subdivideThreshold) <= 0) {
console.error('\'subdivideThreshold\' must be greater than zero.');
process.exit(1);
console.error("'subdivideThreshold' must be greater than zero.");
process.exit(1);
}

// Process SVG

const inputPath = commander.args[0];
const inputDir = path.dirname(inputPath);
const outputFileName = path.basename(inputPath, '.svg') + '.geojson';
const outputFileName = path.basename(inputPath, ".svg") + ".geojson";
let outputPath;
if (commander.args.length > 1) {
outputPath = commander.args[1];
if (!path.extname(outputPath)) {
outputPath = path.join(outputPath, outputFileName);
}
outputPath = commander.args[1];
if (!path.extname(outputPath)) {
outputPath = path.join(outputPath, outputFileName);
}
} else {
outputPath = path.join(inputDir, outputFileName);
outputPath = path.join(inputDir, outputFileName);
}

const svg = fs.readFileSync(inputPath, 'utf8');
const svg = fs.readFileSync(inputPath, "utf8");
const convertOptions = {};
if (options.center) {
convertOptions.center = options.center.split(',').map(coord => parseFloat(coord));
convertOptions.center = options.center.split(",").map((coord) => parseFloat(coord));
}
if (options.width) {
convertOptions.width = parseFloat(options.width);
convertOptions.width = parseFloat(options.width);
}
if (options.wbearingidth) {
convertOptions.bearing = parseFloat(options.bearing);
convertOptions.bearing = parseFloat(options.bearing);
}
if (options.subdivideThreshold) {
convertOptions.subdivideThreshold = parseFloat(options.subdivideThreshold);
convertOptions.subdivideThreshold = parseFloat(options.subdivideThreshold);
}
try {
const { geojson, errors } = convertSVG(svg, convertOptions)
errors.forEach((e) => {
console.warn(e);
});
fs.writeFileSync(outputPath, JSON.stringify(geojson, null, options.pretty ? 2 : 0));
console.info('Converted SVG to GeoJSON.');
const { geojson, errors } = convertSVG(svg, convertOptions);
errors.forEach((e) => {
console.warn(e);
});
fs.writeFileSync(outputPath, JSON.stringify(geojson, null, options.pretty ? 2 : 0));
console.info("Converted SVG to GeoJSON.");
} catch (e) {
console.error(e);
console.error(e);
}
Loading

0 comments on commit 6609910

Please sign in to comment.