Skip to content

Commit

Permalink
lint: modernize usage of babel (pypi#17094)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheman authored Nov 18, 2024
1 parent 6d1f9aa commit 9134ef2
Show file tree
Hide file tree
Showing 15 changed files with 642 additions and 859 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /opt/warehouse/src/
# However, we do want to trigger a reinstall of our node.js dependencies anytime
# our package.json changes, so we'll ensure that we're copying that into our
# static container prior to actually installing the npm dependencies.
COPY package.json package-lock.json .babelrc /opt/warehouse/src/
COPY package.json package-lock.json babel.config.js /opt/warehouse/src/

# Installing npm dependencies is done as a distinct step and *prior* to copying
# over our static files so that, you guessed it, we don't invalidate the cache
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ default:
mkdir -p .state
touch .state/docker-build-base

.state/docker-build-static: Dockerfile package.json package-lock.json .babelrc
.state/docker-build-static: Dockerfile package.json package-lock.json babel.config.js
# Build our static container for this project.
docker compose build --force-rm static

Expand Down
16 changes: 16 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ services:
volumes:
- ./warehouse:/opt/warehouse/src/warehouse:z
- ./webpack.config.js:/opt/warehouse/src/webpack.config.js:z
- ./.babelrc:/opt/warehouse/src/.babelrc:z
- ./babel.config.js:/opt/warehouse/src/babel.config.js:z
- ./.stylelintrc.json:/opt/warehouse/src/.stylelintrc.json:z
- ./tests/frontend:/opt/warehouse/src/tests/frontend:z
- ./bin:/opt/warehouse/src/bin:z
Expand Down
1,415 changes: 594 additions & 821 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint:fix": "eslint 'warehouse/static/js/**' 'warehouse/admin/static/js/**' 'tests/frontend/**' --ignore-pattern 'warehouse/static/js/vendor/**' --fix",
"stylelint": "stylelint '**/*.scss' --cache",
"stylelint:fix": "stylelint '**/*.scss' --cache --fix",
"test": "jest --coverage"
"test": "NODE_OPTIONS='$NODE_OPTIONS --experimental-vm-modules' jest --coverage"
},
"jest": {
"setupFilesAfterEnv": [
Expand All @@ -34,13 +34,12 @@
"sweetalert2": "11.4.8"
},
"devDependencies": {
"@babel/core": "^7.21.3",
"@babel/eslint-parser": "^7.21.3",
"@babel/preset-env": "^7.21.4",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@stylistic/eslint-plugin-js": "^2.1.0",
"@testing-library/dom": "^9.2.0",
"@testing-library/jest-dom": "^5.16.5",
"babel-jest": "^29.5.0",
"babel-jest": "^29.7.0",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
Expand Down Expand Up @@ -75,8 +74,8 @@
"jquery": true
},
"extends": "eslint:recommended",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
Expand Down
12 changes: 6 additions & 6 deletions tests/frontend/github_repo_info_controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("GitHub Repo Info controller", () => {
message: "Not Found",
documentation_url: "https://docs.github.com/rest/reference/repos#get-a-repository",
}),
{ status: 404 }
{ status: 404 },
);

startStimulus();
Expand All @@ -115,7 +115,7 @@ describe("GitHub Repo Info controller", () => {
forks_count: 200,
open_issues_count: 300,
total_count: 50,
})
}),
);

startStimulus();
Expand All @@ -128,16 +128,16 @@ describe("GitHub Repo Info controller", () => {
expect(fetch.mock.calls.length).toEqual(6);

const stargazersCount = el.querySelector(
"[data-github-repo-info-target='stargazersCount']"
"[data-github-repo-info-target='stargazersCount']",
);
const forksCount = el.querySelector(
"[data-github-repo-info-target='forksCount']"
"[data-github-repo-info-target='forksCount']",
);
const openIssuesCount = el.querySelector(
"[data-github-repo-info-target='openIssuesCount']"
"[data-github-repo-info-target='openIssuesCount']",
);
const openPRsCount = el.querySelector(
"[data-github-repo-info-target='openPRsCount']"
"[data-github-repo-info-target='openPRsCount']",
);

expect(stargazersCount.textContent).toBe("100");
Expand Down
2 changes: 1 addition & 1 deletion tests/frontend/password_strength_gauge_controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Password strength gauge controller", () => {
const gauge = document.getElementById("gauge");
const ZXCVBN_LEVELS = [0, 1, 2, 3, 4];
ZXCVBN_LEVELS.forEach(i =>
expect(gauge).not.toHaveClass(`password-strength__gauge--${i}`)
expect(gauge).not.toHaveClass(`password-strength__gauge--${i}`),
);
expect(gauge).not.toHaveAttribute("data-zxcvbn-score");
expect(gauge.querySelector(".sr-only")).toHaveTextContent("Password field is empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export default class extends Controller {
mode: "cors",
};
const fetchRepoData = fetch(this.urlValue, fetchParams).then((response) =>
response.ok === true ? response.json() : null
response.ok === true ? response.json() : null,
);

const fetchIssueData = fetch(this.issueUrlValue, fetchParams).then(
(response) => (response.ok === true ? response.json() : null)
(response) => (response.ok === true ? response.json() : null),
);

const allData = Promise.all([fetchRepoData, fetchIssueData]);
Expand All @@ -52,7 +52,7 @@ export default class extends Controller {
PRs: res[0].open_issues_count - res[1].total_count,
};
this.githubRepoInfoOutlets.forEach((outlet) =>
outlet.updateStats(stats)
outlet.updateStats(stats),
);
})
// swallow errors, we don't want to show them to the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ export default class extends Controller {
"state": "opened",
"per_page": 1,
}),
fetchParams
fetchParams,
).then((response) => {
if(response.ok) {
return response.json().then(
(data) => Object.keys(data).length ? response.headers.get("X-Total-Pages") : 0
(data) => Object.keys(data).length ? response.headers.get("X-Total-Pages") : 0,
);
}

console.error(
`Received ${response.status} HTTP code while fetching Gitlab ${project_object} data. The response is "${response.text}"`
`Received ${response.status} HTTP code while fetching Gitlab ${project_object} data. The response is "${response.text}"`,
);

return 0;
Expand All @@ -59,9 +59,9 @@ export default class extends Controller {
const project_api_url = `${GITLAB_API_URL}/projects/${project_id}`;
const project_info = fetch(
project_api_url,
fetchParams
fetchParams,
).then((response) =>
response.ok === true ? response.json() : null
response.ok === true ? response.json() : null,
);

const issues = get_project_objects_count(project_api_url, "issues", fetchParams);
Expand All @@ -80,7 +80,7 @@ export default class extends Controller {
MRs_url: project.web_url + "/-/merge_requests",
};
this.gitlabRepoInfoOutlets.forEach((outlet) =>
outlet.updateStats(stats)
outlet.updateStats(stats),
);
})
// swallow errors, we don't want to show them to the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class extends Controller {
let date = timestamp.substr(0, 10).split("-").map(i => parseInt(i));
let time = timestamp.substr(11, 8).split(":").map(i => parseInt(i));
return new Date(
Date.UTC(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]), ...time)
Date.UTC(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]), ...time),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class extends Controller {
e => {
console.error(e); // eslint-disable-line no-console
this.hideMessage(); // default to hiding the message on errors
}
},
);
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ export default class extends Controller {
// For our uses, we're going to consider any password that has ever appeared in
// a breach to be insecure, even if only once.
let isBreached = responseText.split("\n").some(
line => line.toLowerCase().split(":")[0] === hashedPassword.slice(5)
line => line.toLowerCase().split(":")[0] === hashedPassword.slice(5),
);
if (isBreached) {
this.showMessage();
Expand Down
2 changes: 1 addition & 1 deletion warehouse/static/js/warehouse/utils/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function submitTriggers() {
button.addEventListener(
"click",
removeFilter.bind(null, input.value),
false
false,
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions warehouse/static/js/warehouse/utils/webauthn.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const postCredential = async (label, credential, token) => {
cache: "no-cache",
body: formData,
credentials: "same-origin",
}
},
);

return await resp.json();
Expand All @@ -156,7 +156,7 @@ const postAssertion = async (assertion, token, rememberDevice) => {
cache: "no-cache",
body: formData,
credentials: "same-origin",
}
},
);

return await resp.json();
Expand Down Expand Up @@ -189,7 +189,7 @@ export const ProvisionWebAuthn = () => {
"/manage/account/webauthn-provision/options", {
cache: "no-cache",
credentials: "same-origin",
}
},
);

const credentialOptions = await resp.json();
Expand Down Expand Up @@ -219,7 +219,7 @@ export const AuthenticateWebAuthn = () => {
"/account/webauthn-authenticate/options" + window.location.search, {
cache: "no-cache",
credentials: "same-origin",
}
},
);

const assertionOptions = await resp.json();
Expand Down

0 comments on commit 9134ef2

Please sign in to comment.