Embattled Planning Commissioner Dennis Richards filed a lawsuit against the San Francisco Department of Building Inspection on Wednesday, alleging officials revoked permits on a building he co-owns to retaliate for his criticism of the department.

The lawsuit, filed in federal court, claims that DBI officials “brazenly retaliated against Commissioner Richards, a business in which he was an investor, and his business partner in a transparent attempt to silence his criticism and calls for investigation into perceived corruption.”

The lawsuit comes five months after the city yanked nine permits on a four-unit building at 3426-3432 22nd St., a four-unit historic Italianate building that Richards and Noe Valley real estate broker Rachel Swann own. Richards and Swann purchased the building for $2.7 million in 2017 and are attempting to sell it for $7.88 million, after fixing it up and buying out longtime tenants.

The lawsuit alleges DBI officials revoked the permits after Richards blasted the department during a Planning Commission meeting in August for allowing work on an 18th Street building without the proper permits. At the time, Richards stated that he had “lost faith” in the department. Richards has frequently criticized the building department for what he’s alleged is corruption and favoritism.

“Rather than do what a good governmental agency should do when such claims are made — investigate and take steps to reform — DBI acted instead like a crook worried about being exposed,” states the lawsuit.

While builders generally have 30 days to come up with a plan to correct violations before permits are revoked, in Richards’ case the notice of violation and the permit revocation both happened Sept. 30. Only one or two permits a year are ever revoked.

City Zoning Administrator Scott Sanchez, however, has said that the 22nd Street violations are serious and need to be corrected. This includes 14 windows installed in the rear of the building that don’t conform to historic standards, four skylights added to the roof without permits, and exceeding parking limits. Marketing materials tout the property’s 12 parking spaces, but the city allows only six spots in the building.

“There are clear violations here of the planning code and the building code and other issues,” Sanchez said late last year.

Richards says that the violations were relatively minor and that he is being targeted because of his frequent criticism of the Department of Building Inspection.

Richards is currently on leave from the Planning Commission. Critics said a planning commissioner who’s in conflict with the building department couldn’t effectively do the job. Others have pointed out that Richards, who regularly rails against speculators and property-flippers, is doing exactly that with his investment in the 22nd Street building.

In December, Richards denied that he was engaged in property flipping. He told The Chronicle at the time that all the tenants in the 22nd Street building requested to be bought out and that he had hoped the tenants paying the lowest rent — a family of Mexican immigrants paying less than $600 a month — would stay, but they wanted to relocate.

Several members of the Board of Supervisors, including Dean Preston and Matt Haney, have called on Richards to resign. Board of Supervisors President Norman Yee said he hasn’t made a decision on Richards’ future on the commission.

“When Richards asked for a leave of absence, I agreed,” said Yee. “This will give him an opportunity to decide what’s best for the city and less what’s better only for him.”

DBI spokesman John Murray said the department “can’t comment on pending litigation.”

John Coté, spokesman for City Attorney Dennis Herrera, said the city attorney’s office “will review the lawsuit once we have been served with it, and we will address this matter in court.”

J.K. Dineen is a San Francisco Chronicle staff writer. Email: jdineen@sfchronicle.com Twitter: @sfjkdineen