Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining code to complete MVP #33

Merged
merged 30 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c35214c
Add remaining code to complete MVP
mcmire Nov 12, 2023
dfba17e
Drop .string('_'), as it doesn't add anything
mcmire Dec 19, 2023
732fc82
Inline working directory path
mcmire Dec 19, 2023
3b18d0e
Remove Vim modeline
mcmire Dec 19, 2023
3c5ec57
Add --help back to usage output; use strict options mode
mcmire Dec 19, 2023
1b5854d
Use more widely used names for working with yargs
mcmire Dec 20, 2023
1aed3b2
Remove OPTIONS from usage
mcmire Dec 20, 2023
8ac9fda
Remove --version as an option
mcmire Dec 20, 2023
3bbb44d
Remove (most of) the istanbul ignores
mcmire Dec 20, 2023
4714fef
Build path in a guaranteed cross-platform way
mcmire Dec 20, 2023
af59f53
Remove another 'istanbul ignore' directive
mcmire Dec 20, 2023
ca73b38
No need to hold on to the '_' name
mcmire Dec 20, 2023
c66bb2a
Remove another 'istanbul ignore' directive
mcmire Dec 20, 2023
e0ca478
Fix formatting
mcmire Dec 20, 2023
d034718
Don't just log the error stack, log the whole thing
mcmire Dec 20, 2023
75af066
TEMP: Don't lint tmp/
mcmire Dec 20, 2023
8a025a0
Add passing/failing numbers to report
mcmire Dec 20, 2023
5989401
Clarify JSDocs for buildRule
mcmire Dec 20, 2023
bc3f58e
Refactor require-source-directory and simplify message
mcmire Dec 20, 2023
7208204
Remove chalk
mcmire Dec 20, 2023
0ba1e29
Remove extraneous line from main.test.ts
mcmire Dec 20, 2023
ca61ee5
Fix tests
mcmire Dec 20, 2023
69e1b8e
Add missing tests for require-source-directory
mcmire Dec 20, 2023
dda0390
Make the 'does not exit immediately' tests better
mcmire Dec 21, 2023
b33c692
Limit the number of default repos
mcmire Dec 21, 2023
c8c06c6
Refactor better
mcmire Dec 21, 2023
06d1931
Silence jest-haste-map errors
mcmire Dec 21, 2023
475b273
Add tests for pass and fail
mcmire Dec 21, 2023
8b53d27
Refactor the check in and document it
mcmire Dec 21, 2023
fc48493
Fix lint violation
mcmire Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ module.exports = {
'@metamask/eslint-config-nodejs',
],
},

{
files: ['src/cli.ts'],
parserOptions: {
sourceType: 'script',
},
rules: {
// It's okay if this file has a shebang; it's meant to be executed
// directly.
'n/shebang': 'off',
},
},
],

ignorePatterns: [
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ node_modules/
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Repositories that this tool clones, and other temporary data
tmp
6 changes: 2 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: ['./src/**/*.ts'],
collectCoverageFrom: ['./src/**/*.ts', '!./src/cli.ts'],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
Expand Down Expand Up @@ -159,9 +159,7 @@ module.exports = {
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
testPathIgnorePatterns: ['/node_modules/', '/tmp'],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"bin": "./dist/cli.js",
"files": [
"dist/cjs/**",
"dist/esm/**",
Expand All @@ -44,14 +45,16 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepack": "./scripts/prepack.sh",
"run-tool": "ts-node --swc src/cli.ts",
"test": "jest && jest-it-up",
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/utils": "^8.2.0",
"chalk": "^4.1.2",
"dependency-graph": "^0.11.0",
"execa": "^5.1.1"
"execa": "^5.1.1",
"yargs": "^17.7.2"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.3.1",
Expand Down
22 changes: 22 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

import {
DEFAULT_PROJECT_NAMES,
DEFAULT_CACHED_REPOSITORIES_DIRECTORY_PATH,
} from './constants';
import { main } from './main';

main({
argv: process.argv,
stdout: process.stdout,
stderr: process.stderr,
config: {
cachedRepositoriesDirectoryPath: DEFAULT_CACHED_REPOSITORIES_DIRECTORY_PATH,
defaultProjectNames: DEFAULT_PROJECT_NAMES,
},
}).catch((error) => {
console.error(error);
process.exitCode = 1;
});

// vi: ft=typescript
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
122 changes: 122 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,127 @@
import path from 'path';

/**
* The name of this project. Used to exclude this repo as a lintable project.
*/
const THIS_PROJECT_NAME = 'module-lint';

/**
* The root directory of this project.
*/
const THIS_PROJECT_DIRECTORY_PATH = path.resolve(__dirname, '..');

/**
* The number of milliseconds in an hour, used to determine when to pull the
* latest changes for previously cached repositories.
*/
export const ONE_HOUR = 60 * 60 * 1000;

/**
* Wherever the tool was run.
*/
export const WORKING_DIRECTORY_PATH = process.cwd();
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved

/**
* The usage text printed when the user requests help or provides invalid input.
*/
export const USAGE_TEXT = `
Analyzes one or more repos for divergence from a template repo.

${THIS_PROJECT_NAME} OPTIONS [ARGUMENTS...]
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved

Pass the names of one or more MetaMask repositories to lint them, or pass
nothing to lint all MetaMask repositories.
`.trim();

/**
* In order to lint a remote repository, that repository must be cloned first.
* This is the temporary directory where the clone lives.
*/
export const DEFAULT_CACHED_REPOSITORIES_DIRECTORY_PATH = path.join(
THIS_PROJECT_DIRECTORY_PATH,
'tmp/repositories',
mcmire marked this conversation as resolved.
Show resolved Hide resolved
);

/**
* The name of the template repository that project repositories will be
* compared to. The only such repository we have is the module template.
*/
export const DEFAULT_TEMPLATE_REPOSITORY_NAME = 'metamask-module-template';

/**
* All of the remote MetaMask repositories that will be linted if a list is not
* explicitly provided.
*/
export const DEFAULT_PROJECT_NAMES = [
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
'abi-utils',
'action-create-release-pr',
'action-is-release',
'action-npm-publish',
'action-publish-gh-pages',
'action-publish-release',
'action-require-additional-reviewer',
'action-tech-challenge-setup',
'action-utils',
'actions-gh-pages-test-repo',
'actions-test-repo',
'auto-changelog',
'bip39',
'cla-signature-bot',
'contract-metadata',
'contributor-docs',
'core',
'create-release-branch',
'eslint-config',
'eth-block-tracker',
'eth-json-rpc-filters',
'eth-json-rpc-infura',
'eth-json-rpc-middleware',
'eth-json-rpc-provider',
'eth-method-registry',
'eth-phishing-detect',
'eth-sig-util',
'eth-token-tracker',
'etherscan-link',
'ethjs',
'ethjs-abi',
'ethjs-contract',
'ethjs-filter',
'ethjs-format',
'ethjs-provider-http',
'ethjs-query',
'ethjs-rpc',
'ethjs-schema',
'ethjs-unit',
'ethjs-util',
'extension-port-stream',
'forwarder',
'jazzicon',
'json-rpc-engine',
'json-rpc-middleware-stream',
'logo',
'metamask-eth-abis',
'metamask-module-template',
'metamask-monorepo-template',
'monorepo-actions-test',
'nonce-tracker',
'number-to-bn',
'object-multiplex',
'obs-store',
'oss-attribution-generator',
'phishing-warning',
'post-message-stream',
'providers',
'rpc-errors',
'safe-event-emitter',
'scure-bip39',
'state-log-explorer',
'swappable-obj-proxy',
'tech-challenge-setup',
'technical-challenge-shared-libraries',
'test-dapp',
'types',
'utils',
'vault-decryptor',
'web3-provider-engine',
'web3-stream-provider',
];
Loading