Skip to content

Commit

Permalink
Upgrade eslint (#1014)
Browse files Browse the repository at this point in the history
It's apparently forced now to use the eslint.config.js instead of
.eslintrc

It got more strict with requiring the underscore on unused vars like
`catch(_err)` , but that was all

Closes #1012
Closes #995
Closes #992

## Launch Checklist

<!-- Thanks for the PR! Feel free to add or remove items from the
checklist. -->


 - [ ] Briefly describe the changes in this PR.
 - [ ] Link to related issues.
- [ ] Include before/after visuals or gifs if this PR includes visual
changes.
 - [ ] Write tests for all new functionality.
 - [ ] Add an entry to `CHANGELOG.md` under the `## main` section.
  • Loading branch information
birkskyum authored Jan 21, 2025
1 parent b429bb1 commit cd7d607
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 586 deletions.
46 changes: 0 additions & 46 deletions .eslintrc

This file was deleted.

11 changes: 5 additions & 6 deletions build/release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const changelog = fs.readFileSync(changelogPath, 'utf8');
*/
const regex = /^## (\d+\.\d+\.\d+.*?)\n(.+?)(?=\n^## \d+\.\d+\.\d+.*?\n)/gms;

let releaseNotes = [];
const releaseNotes = [];
let match;
// eslint-disable-next-line no-cond-assign
while (match = regex.exec(changelog)) {
releaseNotes.push({
'version': match[1],
'changelog': match[2].trim(),
});
releaseNotes.push({
'version': match[1],
'changelog': match[2].trim(),
});
}

const latest = releaseNotes[0];
Expand All @@ -44,5 +44,4 @@ const templatedReleaseNotes = `${header}
${latest.changelog}`;

// eslint-disable-next-line eol-last
process.stdout.write(templatedReleaseNotes.trimEnd());
2 changes: 1 addition & 1 deletion cypress/e2e/accessibility.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("accessibility", () => {
let { beforeAndAfter, get, when, then } = new MaputnikDriver();
const { beforeAndAfter, get, when, then } = new MaputnikDriver();
beforeAndAfter();

describe("skip links", () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/history.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("history", () => {
let { beforeAndAfter, when, get, then } = new MaputnikDriver();
const { beforeAndAfter, when, get, then } = new MaputnikDriver();
beforeAndAfter();

let undoKeyCombo: string;
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/i18n.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("i18n", () => {
let { beforeAndAfter, get, when, then } = new MaputnikDriver();
const { beforeAndAfter, get, when, then } = new MaputnikDriver();
beforeAndAfter();

describe("language detector", () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/keyboard.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("keyboard", () => {
let { beforeAndAfter, given, when, get, then } = new MaputnikDriver();
const { beforeAndAfter, given, when, get, then } = new MaputnikDriver();
beforeAndAfter();
describe("shortcuts", () => {
beforeEach(() => {
Expand Down
28 changes: 14 additions & 14 deletions cypress/e2e/layers.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { v1 as uuid } from "uuid";
import { MaputnikDriver } from "./maputnik-driver";

describe("layers", () => {
let { beforeAndAfter, get, when, then } = new MaputnikDriver();
const { beforeAndAfter, get, when, then } = new MaputnikDriver();
beforeAndAfter();
beforeEach(() => {
when.setStyle("both");
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("layers", () => {
});
describe("background", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "background",
});
then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
Expand All @@ -117,7 +117,7 @@ describe("layers", () => {
describe("modify", () => {
function createBackground() {
// Setup
let id = uuid();
const id = uuid();

when.selectWithin("add-layer.layer-type", "background");
when.setValue("add-layer.layer-id.input", "background:" + id);
Expand All @@ -139,11 +139,11 @@ describe("layers", () => {
describe("layer", () => {
it("expand/collapse");
it("id", () => {
let bgId = createBackground();
const bgId = createBackground();

when.click("layer-list-item:background:" + bgId);

let id = uuid();
const id = uuid();
when.setValue("layer-editor.layer-id.input", "foobar:" + id);
when.click("min-zoom");

Expand Down Expand Up @@ -219,7 +219,7 @@ describe("layers", () => {

describe("comments", () => {
let bgId: string;
let comment = "42";
const comment = "42";

beforeEach(() => {
bgId = createBackground();
Expand Down Expand Up @@ -320,11 +320,11 @@ describe("layers", () => {

// TODO
it.skip("parse error", () => {
let bgId = createBackground();
const bgId = createBackground();

when.click("layer-list-item:background:" + bgId);

let errorSelector = ".CodeMirror-lint-marker-error";
const errorSelector = ".CodeMirror-lint-marker-error";
then(get.elementByTestId(errorSelector)).shouldNotExist();

when.click(".CodeMirror");
Expand All @@ -339,7 +339,7 @@ describe("layers", () => {

describe("fill", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "fill",
layer: "example",
});
Expand All @@ -361,7 +361,7 @@ describe("layers", () => {

describe("line", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "line",
layer: "example",
});
Expand All @@ -385,7 +385,7 @@ describe("layers", () => {

describe("symbol", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "symbol",
layer: "example",
});
Expand All @@ -404,7 +404,7 @@ describe("layers", () => {

describe("raster", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "raster",
layer: "raster",
});
Expand All @@ -423,7 +423,7 @@ describe("layers", () => {

describe("circle", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "circle",
layer: "example",
});
Expand All @@ -442,7 +442,7 @@ describe("layers", () => {

describe("fill extrusion", () => {
it("add", () => {
let id = when.modal.fillLayers({
const id = when.modal.fillLayers({
type: "fill-extrusion",
layer: "example",
});
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/map.cy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("map", () => {
let { beforeAndAfter, get, when, then } = new MaputnikDriver();
const { beforeAndAfter, get, when, then } = new MaputnikDriver();
beforeAndAfter();
describe("zoom level", () => {
it("via url", () => {
let zoomLevel = 12.37;
const zoomLevel = 12.37;
when.setStyle("geojson", zoomLevel);
then(get.elementByTestId("maplibre:ctrl-zoom")).shouldBeVisible();
then(get.elementByTestId("maplibre:ctrl-zoom")).shouldContainText(
Expand All @@ -14,7 +14,7 @@ describe("map", () => {
});

it("via map controls", () => {
let zoomLevel = 12.37;
const zoomLevel = 12.37;
when.setStyle("geojson", zoomLevel);
then(get.elementByTestId("maplibre:ctrl-zoom")).shouldBeVisible();
when.clickZoomIn();
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/modal-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class ModalDriver {
fillLayers: (opts: { type: string; layer?: string; id?: string }) => {
// Having logic in test code is an anti pattern.
// This should be splitted to multiple single responsibility functions
let type = opts.type;
let layer = opts.layer;
const type = opts.type;
const layer = opts.layer;
let id;
if (opts.id) {
id = opts.id;
Expand Down
16 changes: 8 additions & 8 deletions cypress/e2e/modals.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("modals", () => {
let { beforeAndAfter, when, get, then } = new MaputnikDriver();
const { beforeAndAfter, when, get, then } = new MaputnikDriver();
beforeAndAfter();

beforeEach(() => {
Expand All @@ -25,7 +25,7 @@ describe("modals", () => {

describe("when click open url", () => {
beforeEach(() => {
let styleFileUrl = get.exampleFileUrl();
const styleFileUrl = get.exampleFileUrl();

when.setValue("modal:open.url.input", styleFileUrl);
when.click("modal:open.url.button");
Expand Down Expand Up @@ -70,7 +70,7 @@ describe("modals", () => {
it("public source");

it("add new source", () => {
let sourceId = "n1z2v3r";
const sourceId = "n1z2v3r";
when.setValue("modal:sources.add.source_id", sourceId);
when.select("modal:sources.add.source_type", "tile_vector");
when.select("modal:sources.add.scheme_type", "tms");
Expand All @@ -84,7 +84,7 @@ describe("modals", () => {
});

it("add new raster source", () => {
let sourceId = "rastertest";
const sourceId = "rastertest";
when.setValue("modal:sources.add.source_id", sourceId);
when.select("modal:sources.add.source_type", "tile_raster");
when.select("modal:sources.add.scheme_type", "xyz");
Expand Down Expand Up @@ -159,7 +159,7 @@ describe("modals", () => {
});
});
it("glyphs url", () => {
let glyphsUrl = "http://example.com/{fontstack}/{range}.pbf";
const glyphsUrl = "http://example.com/{fontstack}/{range}.pbf";
when.setValue("modal:settings.glyphs", glyphsUrl);
when.click("modal:settings.name");
then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
Expand All @@ -168,7 +168,7 @@ describe("modals", () => {
});

it("maptiler access token", () => {
let apiKey = "testing123";
const apiKey = "testing123";
when.setValue(
"modal:settings.maputnik:openmaptiles_access_token",
apiKey
Expand All @@ -182,7 +182,7 @@ describe("modals", () => {
});

it("thunderforest access token", () => {
let apiKey = "testing123";
const apiKey = "testing123";
when.setValue(
"modal:settings.maputnik:thunderforest_access_token",
apiKey
Expand All @@ -194,7 +194,7 @@ describe("modals", () => {
});

it("stadia access token", () => {
let apiKey = "testing123";
const apiKey = "testing123";
when.setValue(
"modal:settings.maputnik:stadia_access_token",
apiKey
Expand Down
61 changes: 61 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import reactRefreshPlugin from 'eslint-plugin-react-refresh';

export default tseslint.config({
extends: [
eslint.configs.recommended,
tseslint.configs.recommended,
],
files: ['**/*.{js,jsx,ts,tsx}'],
ignores: [
"dist/**/*",
],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: {
global: 'readonly'
}
},
settings: {
react: { version: '18.2' }
},
plugins: {
'react': reactPlugin,
'react-hooks': reactHooksPlugin,
'react-refresh': reactRefreshPlugin
},
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true }
],
"@typescript-eslint/no-explicit-any": "off",
'@typescript-eslint/no-unused-vars': [
'warn',
{
varsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
argsIgnorePattern: '^_'
}
],
'no-unused-vars': 'off',
'react/prop-types': 'off',
'no-undef': 'off',
'indent': ['error', 2],
'no-var': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-object-type': 'off',

},
linterOptions: {
reportUnusedDisableDirectives: true,
noInlineConfig: false
}
}
)
Loading

0 comments on commit cd7d607

Please sign in to comment.