Updated eslint prettier and other files

This commit is contained in:
Greg Jacobs
2024-06-04 09:07:17 -04:00
parent 1e4c307f97
commit 6ba29f130f
14 changed files with 259 additions and 12 deletions

1
.eslintignore Normal file
View File

@@ -0,0 +1 @@
dist

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
package-lock.json package-lock.json
node_modules/ node_modules/
codingstandards.txt

11
.prettierrc Normal file
View File

@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "lf"
}

View File

@@ -1,8 +1,44 @@
import globals from "globals"; // .eslintrc.mjs
import pluginJs from "@eslint/js"; export default {
env: {
browser: true,
export default [ es2021: true,
{languageOptions: { globals: {...globals.browser, ...globals.node} }}, },
pluginJs.configs.recommended, extends: [
]; 'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
rules: {
'no-undef': 'error',
'no-unused-vars': 'error',
'no-console': 'warn',
'no-unreachable': 'error',
'no-constant-condition': 'warn',
'no-debugger': 'warn',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty': 'error',
'no-extra-semi': 'error',
'no-irregular-whitespace': 'error',
'no-unexpected-multiline': 'error',
'curly': 'error',
'eqeqeq': 'error',
'no-else-return': 'error',
'no-multi-spaces': 'error',
'no-with': 'error',
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'max-len': ['error', { code: 80 }],
'no-trailing-spaces': 'error',
'eol-last': ['error', 'always'],
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
},
};

View File

@@ -4,7 +4,10 @@
"description": "This project contains several files that perform various tasks. Here's a brief overview of each file:", "description": "This project contains several files that perform various tasks. Here's a brief overview of each file:",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint src --ext .js",
"lint:fix": "eslint src --ext .js --fix",
"format": "prettier src --write --ignore-unknown"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -13,9 +16,9 @@
"author": "Greg Jacobs", "author": "Greg Jacobs",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.4.0",
"eslint": "^9.4.0", "eslint": "^9.4.0",
"globals": "^15.3.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.3.0" "prettier": "^3.3.0"
} }
} }

View File

@@ -0,0 +1,6 @@
javascript:(function() {
var issueType = document.querySelector('.issue-link').textContent.trim();
var ticketNumber = document.querySelector('.issue-link').getAttribute('data-issue-key');
alert('Issue Type: ' + issueType + '\nTicket Number: ' + ticketNumber);
})();

29
src/ideas/newideas.txt Normal file
View File

@@ -0,0 +1,29 @@
import bookmarks and makes a folder in new browser
const fs = require('fs');
const path = require('path');
// Create dist folder
const distPath = path.join(__dirname, 'dist');
fs.mkdirSync(distPath);
// Import browser bookmark file
const bookmarkFilePath = path.join(__dirname, 'path/to/bookmark/file');
const bookmarks = require(bookmarkFilePath);
// Loop through bookmarklets
const bookmarkletsPath = path.join(__dirname, 'src/utils/bookmarklets');
fs.readdirSync(bookmarkletsPath).forEach(file => {
const bookmarkletPath = path.join(bookmarkletsPath, file);
const bookmarklet = fs.readFileSync(bookmarkletPath, 'utf8');
// Create new bookmark for each bookmarklet
const newBookmark = {
name: file,
url: `javascript:${bookmarklet}`
};
bookmarks.push(newBookmark);
});
// Save updated bookmarks
fs.writeFileSync(bookmarkFilePath, JSON.stringify(bookmarks, null, 2));

23
src/ideas/rbcLogin.js Normal file
View File

@@ -0,0 +1,23 @@
javascript:(function() {
var url = 'https://www1.steroyalbank.com/english/netaction/sgne.html';
function loginWithCC(cc) {
var newWindow = window.open(url, '_blank').focus();
newWindow.addEventListener('load', function() {
var userIdInput = newWindow.document.getElementById('USERID');
var passwordInput = newWindow.document.getElementById('PASSWORD');
var signInButton = newWindow.document.querySelector('button[title="Sign In"]');
userIdInput.value = cc;
passwordInput.value = 'password';
signInButton.click();
});
}
var cc = prompt('Enter CC:');
if (cc) {
loginWithCC(cc);
} else {
window.open(url, '_blank').focus();
}
})();

View File

@@ -0,0 +1,21 @@
# Coding Standards
The [`CODINGSTANDARDS.TXT`](../../../../codingstandards.txt) file outlines the coding standards and best practices for the organization. Updating your Prettier and ESLint configurations can help enforce these standards automatically, ensuring consistency across the codebase and reducing the likelihood of errors. Here are some reasons based on the provided standards:
## Code Clarity and Consistency
The document emphasizes the importance of code clarity and consistency. Prettier is an opinionated code formatter that enforces a consistent style by parsing your code and reprinting it with its own rules. ESLint, on the other hand, helps to enforce code quality rules. By updating these configurations, you can ensure that your code adheres to the standards outlined in the document.
## General Principles
The document mentions several principles like "Single responsibility principle", "Small is beautiful", "Consistency", etc. While Prettier and ESLint can't enforce all these principles, they can help with some, especially around consistency and avoiding certain anti-patterns.
## Secure Coding Practices
ESLint, in particular, can be configured with plugins like `eslint-plugin-security` to catch common security mistakes and vulnerabilities, helping to enforce the secure coding practices mentioned in the document.
## Testing
While not directly related to Prettier or ESLint, maintaining clean, consistent, and error-free code can make writing and maintaining tests easier.
Remember, these tools are not a replacement for good coding practices or thorough code reviews, but they can help catch common mistakes and enforce a consistent style, making the code easier to read and maintain.

View File

@@ -0,0 +1,55 @@
# ESLint Configuration
This document provides an overview of the ESLint configuration file `.eslint.config.mjs` used in our project. [ESLint](https://eslint.org/) is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs.
The choices made in this configuration file are based on the Fincentric Programming Standards as outlined in [`CODINGSTANDARDS.TXT`](../../../codingstandards.txt).
## Configuration Details
The configuration file is written in ECMAScript 6 (ES6) module syntax, hence the `.mjs` extension. This allows us to use `import` and `export` statements for better modularity and code organization.
The configuration file is divided into several sections:
- **Environment**: This section defines the environments where your code is designed to run. Each environment brings with it a certain set of predefined global variables.
- **Globals**: This section is used to define global variables that are used across different files in your project.
- **Rules**: This section is the heart of ESLint's configuration. It lists the rules you want ESLint to enforce. The rules chosen reflect the coding standards we follow. For example, we enforce the use of semicolons at the end of statements, consistent indentation, and the use of single quotes for strings.
- **Parser Options**: This section is used to specify the JavaScript language options you want to support. Our project is configured to support ES6 syntax.
- **Plugins**: This section is used to load ESLint plugins. Plugins usually come with a set of rules that they can use to enforce or report on.
- **Extends**: This section is used to specify a configuration that this configuration extends. It helps to maintain a base configuration and extend it for different environments.
## Adherence to Fincentric Programming Standards
The ESLint configuration is designed to enforce the Fincentric Programming Standards. Here are some examples:
- **Code Clarity**: ESLint helps enforce code clarity by flagging overly complex code structures, and by enforcing consistent formatting and indentation.
- **Consistency**: ESLint ensures consistency in code by enforcing a specific coding style. This includes rules about the use of semicolons, quotes, and whitespace.
- **Secure Coding Practices**: ESLint can help enforce secure coding practices by flagging potentially dangerous patterns, such as the use of `eval()`.
- **Testing**: While ESLint itself is not a testing tool, it can help ensure that your code is testable. For example, it can enforce that all functions are small and do one thing, which makes them easier to test.
Please refer to the [CODINGSTANDARDS.TXT](../../../codingstandards.txt) document for a detailed explanation of our coding standards.
## Before Coding Standards
```javascript
import globals, { es2021 } from "globals"
import pluginJs from "@eslint/js"
export default [
{
languageOptions: { globals: globals.browser },
env: { browser: true, es2021: true },
extends: [
"airbnb-base",
"pluginLprettier/recommended",
],
parserOptions: { ecmaVersion: 2021, sourceType: "module" },
rules: {
semi: ["error", "never"],
"prefer-const": "error",
"no-unused-vars": "warn",
}
},
pluginJs.configs.recommended,
]
```

View File

@@ -0,0 +1,37 @@
## Prettier Configuration
This repository uses Prettier, an opinionated code formatter, to ensure that the codebase has a consistent style. The configuration for Prettier is defined in the `.prettierrc` file.
The choices made in the configuration are based on the Fincentric Programming Standards as outlined in the [`CODINGSTANDARDS.TXT`](../../../../../codingstandards.txt) file. Here's a breakdown of the configuration options:
- **Print Width**: This option is set to 80 characters. This is a common standard in many coding style guides. It helps to ensure that the code is easily readable without the need to scroll horizontally.
- **Tab Width**: This option is set to 2 spaces. This is a common standard in many coding style guides. It helps to ensure that the code is indented consistently and is easily readable.
- **Use Tabs**: This option is set to false. This means that spaces are used for indentation. This is in line with the Fincentric Programming Standards which emphasize code clarity and readability.
- **Semi**: This option is set to true. This means that semicolons are always added at the end of statements. This is a common standard in many coding style guides and helps to avoid potential issues related to Automatic Semicolon Insertion (ASI).
- **Single Quote**: This option is set to true. This means that single quotes are used instead of double quotes. This is a common standard in many coding style guides and helps to ensure consistency across the codebase.
- **Trailing Comma**: This option is set to 'none'. This means that trailing commas are not used. This is a common standard in many coding style guides and helps to ensure consistency across the codebase.
- **Bracket Spacing**: This option is set to true. This means that spaces are added inside brackets. This is a common standard in many coding style guides and helps to ensure that the code is easily readable.
- **JSX Bracket Same Line**: This option is set to false. This means that the closing bracket in JSX tags is placed on a new line when the tag spans multiple lines. This is a common standard in many coding style guides and helps to ensure that the code is easily readable.
- **Arrow Function Parentheses**: This option is set to 'always'. This means that parentheses are always added around arrow function parameters. This is a common standard in many coding style guides and helps to ensure consistency across the codebase.
Please ensure that your code adheres to these standards before committing. If you're using VS Code, you can install the Prettier extension and it will automatically format your code on save based on this configuration.
## Before Coding Standards
```json
{
"semi": true,
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": true
}
```

View File

@@ -0,0 +1,23 @@
/**
* Deletes the 'fnc-rbc-session' property from the session storage if it exists.
* If the property exists, it prompts the user for confirmation before deleting.
* If the property does not exist, it displays an alert message.
*/
javascript: (function () {
const rbcSession = sessionStorage.getItem('fnc-rbc-session');
if (rbcSession) {
const sessionValue = JSON.parse(rbcSession);
let properties = '';
for (const key in sessionValue) {
properties += `${key}: ${sessionValue[key]}\n`;
}
const confirmDelete = confirm(`The properties in 'fnc-rbc-session' are:\n\n${properties}\nDo you want to delete 'fnc-rbc-session'?`);
if (confirmDelete) {
sessionStorage.removeItem('fnc-rbc-session');
location.reload();
}
} else {
alert("'fnc-rbc-session' does not exist in session storage.");
}
})();

View File

View File

@@ -1,3 +1,4 @@
// eslint-disable-next-line no-use-before-define
javascript: (function () { javascript: (function () {
function setFlag(_flag, _state) { function setFlag(_flag, _state) {
function setFlagSub(_url, _flag, _state) { function setFlagSub(_url, _flag, _state) {