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

lint: ensure all files are owned by someone #7937

Merged
merged 2 commits into from
Oct 23, 2017
Merged

Conversation

mmalerba
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 21, 2017
function isOwnedBy(path: string, ownedPath: IMinimatch) {
// If the owned path ends with `**` its safe to eliminate whole directories.
if (statSync(path).isFile() || ownedPath.pattern.endsWith('**')) {
return ownedPath.match('/' + path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK match(someStr) ends up creating a Regex under the hood. This could be clearer and faster using indexOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally extracting the regex and working with that, but the matchBase: true didn't seem to be coded into the regex. Anyways I think it caches the regex under the hood instead of recompiling it every time, so it should be fine.

/** Check if the given path is owned by the given owned path matcher. */
function isOwnedBy(path: string, ownedPath: IMinimatch) {
// If the owned path ends with `**` its safe to eliminate whole directories.
if (statSync(path).isFile() || ownedPath.pattern.endsWith('**')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Might be better to move the ownedPath.pattern.endsWith('**') in front since it exits faster, because it doesn't have to hit the file system.

.concat(ignoreOwners.map(path => new Minimatch(path, {dot: true, matchBase: true})));

for (let paths = getChildPaths('.'); paths.length;) {
paths = Array.prototype.concat(...paths
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to get rid of the Array.prototype.concat using a spread: paths = [...paths.filter].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats the equivalent of slice(...paths) not concat(...paths)

// Trim lines.
.map(line => line.trim())
// Remove empty lines and comments.
.filter(line => line && !line.startsWith('#'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't handle cases like /some/path owner1 owner2 #owner3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will? it splits on white space and just cares about the first piece

const ownersFilePath = '.github/CODEOWNERS';

/** Paths that should be ignored when checking for owners coverage. */
const ignoreOwners = ['/node_modules/**', '/dist/**', '/.git/**', '/.idea/**'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really cover all the paths (e.g. there's /.vscode which should also be excluded). Consider populating the list from the .gitignore instead?

// Report an error for any files that didn't match any owned paths.
.filter(path => {
if (statSync(path).isFile()) {
console.error(red(`No code owner found for "${path}".`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to make this look like a Gulp task out, you can use the gulp-util.

// Remove empty lines and comments.
.filter(line => line && !line.startsWith('#'))
// Split off just the path glob and turn it into a regex.
.map(line => new Minimatch(line.split(/\s+/)[0], {dot: true, matchBase: true}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid having to repeat the Minimatch constructor config by concat-ing the ignoreOwners earlier:

readFileSync(ownersFilePath, 'utf8').split('\n')
  // Trim lines.
  .map(line => line.trim())
  // Remove empty lines and comments.
  .filter(line => line && !line.startsWith('#'))
  // Take out the file pattern.
  .map(line => line.split(/\s+/)[0])
  // Add in the paths we're ignoring.
  .concat(ignoreOwners)
  // Turn the paths into regex.
  .map(line => new Minimatch(line, {dot: true, matchBase: true}))

@mmalerba
Copy link
Contributor Author

comments addressed

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Oct 23, 2017
@mmalerba mmalerba merged commit c46ba07 into angular:master Oct 23, 2017
@mmalerba mmalerba deleted the owners branch July 31, 2018 21:19
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants